我正在使用Microsoft.Office.Interop,使用C#掃描Word和Excel文件,我將文件作爲用戶的輸入,將其保存在本地目錄中,然後掃描它的Interop庫。 它在我的本地發佈上工作正常,但是當我在服務器上發佈它時,它沒有掃描Word或Excel文件。 我在我的服務器上安裝了MS-Office,與我在PC上的版本相同。 我還需要做什麼?我已經在我的bin目錄中複製了所需的DLL。 這是我如何讀字的文件使用Microsoft.Office.Interop Word和Excel
public static string word_to_text(string source)
{
Word.Application newApp = new Word.Application();
object Source = source;
object Unknown = Type.Missing;
object miss = System.Reflection.Missing.Value;
object readOnly = true;
Microsoft.Office.Interop.Word.Document docs = newApp.Documents.Open(ref Source, ref miss, ref readOnly, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss);
string totaltext = "";
for (int j = 0; j < docs.Paragraphs.Count; j++)
{
totaltext += " \r\n " + docs.Paragraphs[j + 1].Range.Text.ToString();
}
docs.Close();
newApp.Quit();
return totaltext;
}
我得到這個例外
Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 80070005 Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)).
我按照this post 但是現在我有Excel和Word文件的問題固定它。 在Word文件的情況下,它不從上面的代碼讀取文件,docs對象顯示爲空。 在Excel它的情況下顯示異常
Microsoft Office Excel cannot access the file 'myfile path'. There are several possible reasons: • The file name or path does not exist. • The file is being used by another program. • The workbook you are trying to save has the same name as a currently open workbook.
我讀液得到權利的文件夾,並創建內部SYSTEM32 Here桌面文件夾,我沒有工作這兩種解決方案:( 當我的問題只出現其發佈
您是否收到任何錯誤?我們可以看到一些示例代碼嗎? – ganders
不,我沒有收到任何錯誤 –
錯誤?例外?哪裏? –