使用 Aspose.Total for .NET ,您可以在任何 .NET、C#、ASP.NET 和 VB.NET 应用程序中轻松地将 CGM 文件转换为 XLAM。首先,通过使用 Aspose.PDF for .NET ,您可以将 CGM 导出到 XLSX。之后,通过使用 Aspose.Cells for .NET 电子表格编程 API,您可以将 XLSX 转换为 XLAM。
.NET API 将 CGM 转换为 XLAM
转换要求
从命令行安装为 nuget install Aspose.Total
或通过 Visual Studio 的包管理器控制台使用 Install-Package Aspose.Total
。
或者,从 下载 获取 ZIP 文件中的离线 MSI 安装程序或 DLL。
// supports PDF, CGM, EPUB, TeX, PCL, PS, SVG, XPS, MD, MHTML, XML, and XSLFO file format | |
// load PDF as input file format with an instance of Document class | |
var document = new Document("template.pdf"); | |
// save document in XLSX format | |
document.Save("excel_output.xlsx", Aspose.Pdf.SaveFormat.Xlsx); | |
// load the XLSX file in an instance of Workbook | |
var book = new Workbook("excel_output.xlsx"); | |
// supports XLSB, XLSM, XLT, XLTX, XLTM, XLAM, CSV, TSV, TXT, ODS, DIF, MD, SXC, and FODS file format | |
// save input document as CSV | |
book.Save("output.csv", Aspose.Cells.SaveFormat.Auto); |
通过 C# 将受保护的 CGM 转换为 XLAM
如果您的 CGM 文档受密码保护,则您无法在没有密码的情况下将其转换为 XLAM。使用 API,您可以先使用有效密码打开受保护的文档,然后再进行转换。为了打开加密文件,您可以初始化 Document 类的新实例,并将文件名和密码作为参数传递。
// supports PDF, CGM, EPUB, TeX, PCL, PS, SVG, XPS, MD, MHTML, XML, and XSLFO input file formats | |
// open password protected PDF document | |
Document doc = new Document("input.pdf", "Your@Password"); | |
// save document in XLSX format | |
document.Save("excel_output.xlsx", Aspose.Pdf.SaveFormat.Xlsx); | |
// load the XLSX file in an instance of Workbook | |
var book = new Workbook("excel_output.xlsx"); | |
// supports XLSB, XLSM, XLT, XLTX, XLTM, XLAM, CSV, TSV, TXT, ODS, DIF, MD, SXC, and FODS file format | |
// save input document as CSV | |
book.Save("output.csv", Aspose.Cells.SaveFormat.Auto); |
通过 C# 将 CGM 文件转换为带水印的 XLAM
在将 CGM 文件转换为 XLAM 时,您还可以在输出的 XLAM 文件格式中添加水印。为了添加水印,您可以创建一个新的 Workbook 对象并打开转换后的 XLSX 文档,通过其索引选择 Worksheet,创建一个 Shape 并使用其 AddTextEffect 函数。之后,您可以将 XLSX 文档保存为带水印的 XLAM。
// supports PDF, CGM, EPUB, TeX, PCL, PS, SVG, XPS, MD, MHTML, XML, and XSLFO file format | |
// load PDF as input file format with an instance of Document class | |
var document = new Document("template.pdf"); | |
// save document in XLSX format | |
document.Save("excel_output.xlsx", Aspose.Pdf.SaveFormat.Xlsx); | |
// load the XLSX file in an instance of Workbook | |
var book = new Workbook("excel_output.xlsx"); | |
// get the first default sheet | |
var sheet = book.Worksheets[0]; | |
// add a new shape to ShapesCollection of Worksheet | |
var wordart = sheet.Shapes.AddTextEffect(Aspose.Cells.Drawing.MsoPresetTextEffect.TextEffect1, | |
"CONFIDENTIAL", "Arial Black", 50, false, true, 18, 8, 1, 1, 130, 800); | |
// supports XLSB, XLSM, XLT, XLTX, XLTM, XLAM, CSV, TSV, TXT, ODS, DIF, MD, SXC, and FODS file format | |
// save input document as CSV | |
book.Save("output.csv", Aspose.Cells.SaveFormat.Auto); |