我遇到了打擊代碼,我需要更改Excel頁面設置(方向縮放或任何屬性,但默認打印機不可用的問題,我didn'噸有permessions訪問打印機或發現所以這段代碼引發的異常pagesetup excel工作表和我沒有訪問控制打印機
xlApp = new Excel.Application();
book = xlApp.Workbooks.Open(fileFullPath);
xlApp.Visible = false;
xlApp.DisplayAlerts = false;
var with1 = book.Worksheets[sheetName].PageSetup;
with1.zoom = false;
with1.FitToPagesWide = 1;
with1.FitToPagesTall = 1;
with1.Orientation = XlPageOrientation.xlLandscape;
的例外是:
Exception: System.Runtime.InteropServices.COMException
Message: Unable to set the Zoom property of the PageSetup class
Target Site: Void CheckThrowException(Int32, System.Dynamic.ExcepInfo ByRef, UInt32, System.String)
Source: Microsoft Excel
Stack Trace: at System.Dynamic.ComRuntimeHelpers.CheckThrowException(Int32 hresult, ExcepInfo& excepInfo, UInt32 argErr, String message)
at CallSite.Target(Closure , CallSite , ComObject , Boolean)
at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
at CallSite.Target(Closure , CallSite , Object , Boolean)
at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
at ExcelProcessing.ThumbGeneration.ExcelSheetSnapShoot(String fileFullPath, String thumbDir, String sheetName, String thumbResolution, String cropArea, String PDFFilesDir)
注: 異常發生時,沒有發現打印機作爲默認時改變頁面佈局屬性拋出這個異常,所以我編輯到任何其他的東西出口excel文件作爲lanscape PDF
哪裏和有什麼例外? ('xlApp.Visible = false'是無用的,因爲創建後不可見) – stenci
我添加了這個錯誤發生的異常,當前用戶無法訪問默認打印機(打印機未找到或沒有權限) – user2209162