如何使用互操作将 .xlsx 文件另存为 Unicode 文本?
How can I save an .xlsx file as Unicode text using interop?
我必须构建一个制作报表的桌面应用程序。我需要它真正对用户友好,报告是希伯来语,所以它必须是 Unicode 而不是普通的 .csv 文件,否则我会得到问号。我想接收报告的文件路径(比如 c:\folder\file.xlsx
) 并能够将原始文件的副本作为 Unicode 文本文件保存在另一个位置。帮助?
与 this guy 相同的问题。
"I need to use the saveas() from Microsoft.office.interop.excel but I can't figure how to do it "
添加这个:
using Excel = Microsoft.Office.Interop.Excel;
然后使用此代码:
Excel.Application app = new Excel.Application();
try
{
app.DisplayAlerts = false;
app.Visible = false;
Excel.Workbook book = app.Workbooks.Open("D:\test.xlsx");
book.SaveAs(Filename: "D:\test.txt", FileFormat: Excel.XlFileFormat.xlUnicodeText,
AccessMode: Excel.XlSaveAsAccessMode.xlNoChange,
ConflictResolution: Excel.XlSaveConflictResolution.xlLocalSessionChanges);
}
finally
{
app.Quit();
}
"D:\test.xlsx"
是您输入的 excel 文件名,"D:\test.txt"
是您的 unicode 文本输出文件名。