gpt4 book ai didi

c# - Excel 打印预览

转载 作者:行者123 更新时间:2023-12-04 20:00:42 26 4
gpt4 key购买 nike

以下是我为 Excel 文档打印预览的代码。

编译成功。

但预览窗口不可见。任何机构都可以指出我的错误是什么。是否需要添加更多编码或 dll。

(注:文档包含数据)

        Excel.Application excelApp = new Excel.Application();

Excel.Workbook wb = excelApp.Workbooks.Open(@"C:\\Documents and Settings\\Admin\\Desktop\\DoCoMo\\news5.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);
Excel.Worksheet ws = (Excel.Worksheet)wb.Worksheets[1];
bool userDidntCancel = excelApp.Dialogs[Excel.XlBuiltInDialog.xlDialogPrintPreview].Show(
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, 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, Type.Missing, Type.Missing);




GC.Collect();
GC.WaitForPendingFinalizers();
wb.Close(false, Type.Missing, Type.Missing);
excelApp.Quit();

最佳答案

您可能必须手动显示 Excel 窗口:

excelApp.Visible = true;

但是,我听说它们是与特定 Excel 版本相关的一些问题(它可能适用于某些人,而不适用于其他人)。

关于c# - Excel 打印预览,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2047059/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com