2012-03-28 34 views
5

Opracowałem aplikację WinForm z VB.Net (VS2010) z zainstalowanym pakietem Office 2010 Professional i platformą 64-bitową z systemem Windows 7. Program otwiera dokument w formacie .doc i .rtf i próbuje zapisać go w formacie htm. Używam następujące polecenia:SaveAs2 For Word 2010 nie działa z komputerem PC z programem Word 2007

Dim sFilePath jako String = "C: \ abc \ file.doc"

 Dim oApp As New Microsoft.Office.Interop.Word.Application 
     Dim oDoc As New Microsoft.Office.Interop.Word.Document 
     Dim sTempFileName As String = System.IO.Path.GetTempFileName() 
     oDoc = oApp.Documents.Open(sFilePath) 
     oApp.Visible = False 
     oDoc = oApp.ActiveDocument 
     oDoc.SaveAs2(sTempFileName, FileFormat:=WdSaveFormat.wdFormatHTML,CompatibilityMode:=Microsoft.Office.Interop.Word.WdCompatibilityMode.wdWord2007) 
     oDoc.Close() 
     oApp.Quit() 
     oDoc = Nothing 
     oApp = Nothing 

Wszystko idzie dobrze z rozwojem i działa na rzecz rozwoju PC, ale kiedy opublikować go w trybie offline instalacji i wdrożenia na komputerze klienckim z systemem Windows XP i pakietem Office 2007, powoduje błąd w linii oDoc.SaveAs2 i awarie programu. Mam dość google, ale nie mogłem znaleźć rozwiązania. Ktoś proszę mi pomóc ASAP

Odpowiedz

3

From MSDN

SaveAs2
Metoda ta pojawia się w IntelliSense w Word 2007 projektów, które zwalczają .NET Framework 4. Jednakże, właściwość ta nie może być używana w programie Word 2007 projektów

Przy okazji, jeśli wyszukasz na tej stronie, znajdziesz odpowiedź na swój problem here

Możesz sprawdzić wersję obecnego programu Word zainstalowanego na urządzeniu ser PC przy użyciu tego kodu:

string v = _myWordApp.Version; 
switch(v) 
{ 
    case "7.0": 
    case "8.0": 
    case "9.0": 
    case "10.0": 
    _myWordDoc.SaveAs2000(ref _documentFile, ref _nothing, ref _nothing, ref _nothing, 
     ref _nothing, ref _nothing, ref _nothing, ref _nothing, 
     ref _nothing, ref _nothing, ref _nothing); 
     break; 
    case "11.0": 
    case "12.0" 
    _myWordDoc.SaveAs(ref _documentFile, ref _nothing, ref _nothing, ref _nothing, 
     ref _nothing, ref _nothing, ref _nothing, ref _nothing, 
     ref _nothing, ref _nothing, ref _nothing, ref _nothing, 
     ref _nothing, ref _nothing, ref _nothing, ref _nothing); 
    case "14.0" 
    _myWordDoc.SaveAs2(ref _documentFile, ref WdSaveFormat.wdFormatHTML, 
       ref _nothing, ref _nothing, ref _nothing, 
     ref _nothing, ref _nothing, ref _nothing, ref _nothing, 
     ref _nothing, ref _nothing, ref _nothing, ref _nothing, 
     ref _nothing, ref _nothing, ref _nothing, 
       ref Microsoft.Office.Interop.Word.WdCompatibilityMode.wdWord2007); 
     break; 
    default: 
     errorText = "Not able to get Word Version" 
     break; 
} 

Przepraszamy za kod C#, ale można go łatwo przetłumaczyć.

+1

Dzięki za wyjaśnienie metody "Save" opartej na wersji Office! Otrzymałem 'RPC_E_SERVERFAULT' ponieważ użyłem niepoprawnej metody' SaveAs'. – SliverNinja