来自hresult 0x800a03ec c#的异常打印excel [英] exception from hresult 0x800a03ec c# while print excel

查看:150
本文介绍了来自hresult 0x800a03ec c#的异常打印excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨..



因为我想要从excel文件打印特定的Excel工作表。我写了一些编码来打印Excel工作表但是我在打印时遇到了一些错误文献。



错误详情



异常来自hresult 0x800a03ec



我的代码:



Hi..

As i want Print the Particular Excel Sheet from excel file.i wrote some coding to print Excel sheet but i got some errors while print the document.

Error Details

exception from hresult 0x800a03ec

My Code:

Excel.Application excelApp = new Excel.Application();
            // Open the Workbook:
           // Excel.Workbook wb = excelApp.Workbooks.Open(@"C:\My Documents\Book1.xls", Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,Type.Missing, Type.Missing, Type.Missing, Type.Missing);
            string dtime;
            dtime = day + "-" + month + "-" + year;
            Excel.Workbook wb = excelApp.Workbooks.Open("D:\\Saved Sheets\\" + lblusername + "\\" + file_name + "-" + dtime + ".xlsx", Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
            // Get the first worksheet.
            // (Excel uses base 1 indexing, not base 0.)
            Excel.Worksheet ws = (Excel.Worksheet)wb.Worksheets[1];
            // Print out 1 copy to the default printer:
           //ws.PrintOut(Type.Missing, Type.Missing, Type.Missing, Type.Missing,Type.Missing, Type.Missing, Type.Missing, Type.Missing);
            ws.PrintOutEx(Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
            // Cleanup:
            GC.Collect();
            GC.WaitForPendingFinalizers();

            Marshal.FinalReleaseComObject(ws);

            wb.Close(false, Type.Missing, Type.Missing);
            Marshal.FinalReleaseComObject(wb);

            excelApp.Quit();
            Marshal.FinalReleaseComObject(excelApp);



如何解决此问题请尽快发送解决方案。

谢谢。


How can i solve this Problem Please sent solution ASAP.
Thank You.

推荐答案

在开始打印之前,需要设置 PageSetup [ ^ ]:

1) PrintArea [ ^ ]

2)FitToPageTall [ ^ ]或 FitToPageWide [ ^ ]或缩放 [ ^ ]

3)方向 [ ^ ]

4) PaperSize [ ^ ]

5)等



更多:

Worksheet.Printout [ ^ ]
Before you start printing, you need to set PageSetup[^]:
1) PrintArea[^]
2) FitToPageTall[^] or FitToPageWide[^] or Zoom[^]
3) Orientation[^]
4) PaperSize[^]
5) etc.

More:
Worksheet.Printout[^]


这篇关于来自hresult 0x800a03ec c#的异常打印excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆