2012-03-28 50 views
5

Tôi đã phát triển một ứng dụng WinForm với VB.Net (VS2010) có Office 2010 Professional Installed, và nó là nền tảng Windows 7 64 bit. Chương trình sẽ mở một tài liệu định dạng .doc và .rtf và cố gắng lưu nó ở định dạng htm. Tôi đang sử dụng lệnh sau:SaveAs2 For Word 2010 không hoạt động với Client PC có Word 2007

Dim sFilePath như 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 

Tất cả diễn ra tốt đẹp với sự phát triển và chạy trên máy tính phát triển, nhưng khi tôi xuất bản nó cho ẩn cài đặt và triển khai nó trên Máy khách có Windows XP với Office 2007, nó cung cấp lỗi trên dòng oDoc.SaveAs2 và chương trình bị treo. Tôi đã googled đủ nhưng không thể tìm thấy một giải pháp cho nó. Ai đó hãy giúp tôi càng sớm càng tốt

Trả lời

3

From MSDN

SaveAs2
phương pháp này xuất hiện trong IntelliSense trong Word dự án 2007 nhắm đến nền tảng .NET Framework 4. Tuy nhiên, khách sạn này không thể được sử dụng trong Word 2007 dự án

Nhân tiện, nếu bạn tìm kiếm trên trang web này, bạn sẽ tìm thấy câu trả lời cho sự cố của mình here

Bạn có thể kiểm tra phiên bản của từ hiện tại được cài đặt trên u ser PC sử dụng mã này:

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; 
} 

Xin lỗi vì mã C# nhưng dễ dịch.

+1

Cảm ơn bạn đã làm rõ phương pháp 'Lưu' dựa trên phiên bản Office! Tôi đã nhận được 'RPC_E_SERVERFAULT' vì tôi đã sử dụng phương thức' SaveAs' không chính xác. – SliverNinja

Các vấn đề liên quan