将文档转换为Excel
Contents
 [  Hide ] 将文档从一种格式转换为另一种格式是Aspose.Words的旗舰功能。 您也可以将任何可用的加载格式格式的文档转换为XLSX格式。
将文档转换为XLSX
将文档转换为XLSX是一个相当复杂的过程。 要使用Aspose.Words将文档保存为XLSX格式,请使用XlsxSaveOptions类和SaveFormat枚举中的新Xlsx元素。 如上所述,您可以将文档保存为Aspose.Words到XLSX支持的任何加载格式。
下面的代码示例演示如何将PDF保存为XLSX:
Document doc = new Document(getMyDir() + "Pdf Document.pdf"); doc.save(getArtifactsDir() + "BaseConversions.PdfToXlsx.xlsx"); 有时需要指定其他选项,这可能会影响将文档保存为XLSX的结果。 这些选项可以通过使用XlsxSaveOptions类来指定,其中包含确定如何显示XLSX输出的属性。 
 保存到XLSX时查找和替换
同样使用Aspose.Words,您可以在文档中找到特定的字符串或正则表达式,并将其替换为所需的匹配字符串或正则表达式。 然后,您还可以将结果保存为XLSX格式。
下面的代码示例演示如何执行查找和替换操作并将结果保存为XLSX:
Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); builder.writeln("Ruby bought a ruby necklace."); // We can use a "FindReplaceOptions" object to modify the find-and-replace process. FindReplaceOptions options = new FindReplaceOptions(); // Set the "MatchCase" flag to "true" to apply case sensitivity while finding strings to replace. // Set the "MatchCase" flag to "false" to ignore character case while searching for text to replace. options.setMatchCase(true); doc.getRange().replace("Ruby", "Jade", options); doc.save(getArtifactsDir() + "BaseConversions.FindReplaceXlsx.xlsx");保存到XLSX时指定压缩级别
您还可以使用CompressionLevel属性指定保存时的压缩级别。
下面的代码示例演示如何在保存为XLSX格式时指定压缩级别:
Document doc = new Document(getMyDir() + "Document.docx"); XlsxSaveOptions saveOptions = new XlsxSaveOptions(); saveOptions.setCompressionLevel(CompressionLevel.MAXIMUM); doc.save(getArtifactsDir() + "BaseConversions.CompressXlsx.xlsx", saveOptions);