c# - 工作表导出为 PDF
问题描述
我想将我的 excel 文件的特定工作表导出为 PDF。当我执行 wbk.ExportAsFixedFormat 时,它可以工作,但是当我执行 worksheet.ExportAsFixedFormat 时它不起作用。
有人可以帮助我吗?
我可能必须“激活”工作表?
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Microsoft.Office.Interop.Excel;
namespace XLConvert
{
class Program
{
static void Main(string[] args)
{
Application app = new Application();
Workbook wkb = app.Workbooks.Open(@"C:\Users\ALPIC\Desktop\XL\0000351608.xlsx");
var worksheet = wkb.Sheets["FRA"];
worksheet.ExportAsFixedFormat(XlFixedFormatType.xlTypePDF, @"C:\Users\ALPIC\Desktop\XL\0000351608.pdf");
wkb.Close(false, @"C:\Users\ALPIC\Desktop\XL\0000351608.xlsx");
Marshal.ReleaseComObject(wkb);
}
}
}
谢谢!
解决方案
我发现 !
我试过这个并且它有效:
static void Main(string[] args)
{
Application app = new Application();
Workbook wkb = app.Workbooks.Open(@"C:\Users\ALPIC\Desktop\XL\0000351608.xlsx");
((Worksheet)wkb.Sheets["FRA"]).ExportAsFixedFormat(XlFixedFormatType.xlTypePDF, @"C:\Users\ALPIC\Desktop\XL\0000351608.pdf");; //activates first sheet
wkb.Close(false, @"C:\Users\ALPIC\Desktop\XL\0000351608.xlsx");
Marshal.ReleaseComObject(app);
}
推荐阅读
- python - Discord.py 重写和发送图像 - AttributeError: 'list' object has no attribute 'send'
- java - 是否可以为 Java 11 和 java 模块生成休眠元模型?
- c++ - C 样式字符串数组首先有效,然后不可读
- list - 如何在修改列表时迭代 Xamarin.Forms.Maps Map.Pins 列表?
- php - PHP 7.3 遇到非数字值
- python - 在 tensorflow.keras 中使用 BinaryCrossentropy(from_logits=True) 时应该使用什么作为目标向量
- tensorflow - 远程 Tensorboard 不适用于 SSH 隧道
- julia - 使自定义类型不可广播
- java - 模拟类型必须是:URL,但是是:URL$$PowerMock0
- firebase - 如何获取 QR 码的字符串值并将其存储到 firebase 以便链接到特定用户