【问题标题】:save file as pdf in excel saves all sheets在excel中将文件另存为pdf保存所有工作表
【发布时间】:2015-04-27 17:01:04
【问题描述】:

我在功能区上有一个按钮,可以将其保存为 pdf。但它将所有可见的工作表都保存为pdf。我只希望它保存活动工作表。

private void button1_Click(object sender, RibbonControlEventArgs e)
{
    xl.Application xlApp = Globals.ThisWorkbook.Application;
    ThisWorkbook wb = Globals.ThisWorkbook;
    SaveFileDialog MyFiles = new SaveFileDialog();
    MyFiles.Filter = "PDF Files|*.pdf";
    MyFiles.Title = "Save As...";
    MyFiles.DefaultExt = "*.pdf";
    MyFiles.ShowDialog();
    string path = MyFiles.FileName;
    wb.ExportAsFixedFormat(xl.XlFixedFormatType.xlTypePDF, path);
}

【问题讨论】:

标签: c# excel pdf


【解决方案1】:

您可能需要使用wb.ActiveSheet.ExportAsFixedFormat。这与在普通 VBA 中如何执行此操作也是一致的。

https://msdn.microsoft.com/en-us/library/microsoft.office.tools.excel.workbook.activesheet.aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-1

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-09-22
    • 1970-01-01
    • 1970-01-01
    • 2016-07-23
    • 2022-01-05
    • 1970-01-01
    • 2020-12-13
    相关资源
    最近更新 更多