翻译|使用教程|编辑:吉炜炜|2025-05-12 14:13:07.563|阅读 8 次
概述:Excel 自动化不必太复杂。无论您是转换格式、保护数据还是大规模处理 Excel 文件,Aspose.Cells.LowCode 都能以更少的代码和更高的效率完成所有任务。
# 界面/图表报表/文档/IDE等千款热门软控件火热销售中 >>
相关链接:
以编程方式处理 Excel 文件相对比较麻烦。复杂的 API、数不胜数的选项以及对专业知识的要求,常常会让原本简单的任务变得过于复杂。如果您曾经因为将 Excel 文件转换为 CSV 文件或设置密码保护而淹没在繁琐的文档中,那么您可以了解下Aspose.Cells.LowCode ,它是功能强大且易于访问的库,能够极大地简化 .NET 应用程序中的 Excel 自动化任务。无论您需要转换格式、保护敏感电子表格还是快速处理数据,Aspose.Cells.LowCode 都能提供直观的方法,以更少的代码实现更大的效果。
在这份综合指南中,我将带您了解有关这个改变游戏规则的库的所有信息,并向您展示它如何改变您的 Excel 自动化工作流程。
Aspose.Cells.LowCode 是一个精简的 API 层,构建于强大的 Aspose.Cells 库之上。它旨在通过提供直观、以任务为中心、只需极少编码工作的组件,简化常见的 Excel 操作。您可以将其视为 Excel 自动化的“快速通道”——您可以获得 Aspose.Cells 的全部功能,但复杂性却显著降低。
Aspose.Cells.LowCode 的使用非常简单。首先,通过 NuGet 安装包:
Install-Package Aspose.Cells
该库是独立的,没有外部依赖,部署起来轻而易举。
让我们深入了解一些实际示例,了解 Aspose.Cells.LowCode 如何简化常见的 Excel 操作。
将 Excel 文件转换为 CSV 格式是开发人员面临的最常见任务之一。使用 Aspose.Cells.LowCode,操作非常简单:
using Aspose.Cells.LowCode; // Simple Excel to CSV conversion var loadOptions = new LowCodeLoadOptions { InputFile = "quarterly_sales.xlsx" }; var saveOptions = new LowCodeTextSaveOptions { OutputFile = "quarterly_sales.csv", Format = TextFormat.Csv }; var converter = new TextConverter(loadOptions, saveOptions); converter.Convert();
需要自定义分隔符吗?没问题:
var saveOptions = new LowCodeTextSaveOptions { OutputFile = "quarterly_sales.csv", Format = TextFormat.Csv, Delimiter = ';' // Use semicolon instead of comma };
JSON 是 Web API 的通用语言。将 Excel 数据转换为 JSON 非常简单:
using Aspose.Cells.LowCode; var loadOptions = new LowCodeLoadOptions { InputFile = "product_catalog.xlsx" }; var jsonOptions = new LowCodeJsonSaveOptions { OutputFile = "product_catalog.json", IndentOutput = true }; var jsonConverter = new JsonConverter(loadOptions, jsonOptions); jsonConverter.Convert();
这会将 Excel 表中的每一行转换为 JSON 对象,非常适合 API 响应或数据处理管道。
需要在网站上显示 Excel 数据吗?HTML 转换同样简单:
using Aspose.Cells.LowCode; var loadOptions = new LowCodeLoadOptions { InputFile = "financial_report.xlsx" }; var htmlOptions = new LowCodeHtmlSaveOptions { OutputFile = "financial_report.html", ExportImagesAsBase64 = true // Embeds images directly in the HTML }; var htmlConverter = new HtmlConverter(loadOptions, htmlOptions); htmlConverter.Convert();
PDF 生成传统上很复杂,但 Aspose.Cells.LowCode 使其变得非常简单:
using Aspose.Cells.LowCode; var loadOptions = new LowCodeLoadOptions { InputFile = "annual_report.xlsx" }; var pdfOptions = new LowCodePdfSaveOptions { OutputFile = "annual_report.pdf", Compliance = PdfCompliance.PdfA1b, // For archival purposes EmbedFonts = true }; var pdfConverter = new PdfConverter(loadOptions, pdfOptions); pdfConverter.Convert();
有时您需要以可视化的方式呈现 Excel 数据。生成图像同样简单:
using Aspose.Cells.LowCode; var loadOptions = new LowCodeLoadOptions { InputFile = "sales_dashboard.xlsx" }; var imageOptions = new LowCodeImageSaveOptions { OutputDirectory = "dashboard_images/", ImageFormat = ImageFormat.Png, ScaleFactor = 2.0 // Higher resolution for clearer images }; var imageConverter = new ImageConverter(loadOptions, imageOptions); imageConverter.Convert();
当今世界,数据安全至关重要。Aspose.Cells.LowCode 使保护敏感的 Excel 文件变得非常简单:
using Aspose.Cells.LowCode; // Define a simple protection provider public class SimpleProtectionProvider : AbstractLowCodeProtectionProvider { private readonly string openPwd, writePwd; public SimpleProtectionProvider(string openPwd, string writePwd) { this.openPwd = openPwd; this.writePwd = writePwd; } public override string GetOpenPassword() => openPwd; public override string GetWritePassword() => writePwd; } // Apply password protection var loadOptions = new LowCodeLoadOptions { InputFile = "financial_data.xlsx" }; var saveOptions = new LowCodeSaveOptions { SaveFormat = SaveFormat.Xlsx, OutputFile = "financial_data_protected.xlsx" }; var provider = new SimpleProtectionProvider("OpenSecure123", "EditSecure456"); SpreadsheetLocker.Process(loadOptions, saveOptions, provider);
这适用两级保护:
删除保护同样简单:
// Remove password protection var removeProvider = new SimpleProtectionProvider(string.Empty, string.Empty); SpreadsheetLocker.Process( new LowCodeLoadOptions { InputFile = "financial_data_protected.xlsx" }, new LowCodeSaveOptions { SaveFormat = SaveFormat.Xlsx, OutputFile = "financial_data_unlocked.xlsx" }, removeProvider );
让我们看一些 Aspose.Cells.LowCode 大放异彩的更复杂的场景。
需要将整个目录的 Excel 文件转换为 CSV 文件吗?操作非常简单:
使用返回 Excel 数据的 API 时,您可能需要生成 PDF 报告:
让我们来谈谈投资回报。虽然 Aspose.Cells.LowCode 并非免费,但对于大多数业务场景而言,其收益远远超过成本:
Excel 自动化不必太复杂。Aspose.Cells.LowCode 为传统复杂的开发领域带来了一股清新的气息。凭借其直观的 API、全面的功能集和卓越的易用性,它是那些需要强大 Excel 功能却又不想费心的开发人员的理想解决方案。
无论您是转换格式、保护数据还是大规模处理 Excel 文件,Aspose.Cells.LowCode 都能以更最少的代码和更高的效率完成所有任务。仅凭其节省的时间和成本,它就值得任何处理 Excel 文件的 .NET 项目考虑。
using Aspose.Cells.LowCode;
using System.IO;
string[] excelFiles = Directory.GetFiles("input_folder", "*.xlsx");
foreach (string file in excelFiles)
{
string filename = Path.GetFileNameWithoutExtension(file);
var loadOptions = new LowCodeLoadOptions { InputFile = file };
var saveOptions = new LowCodeTextSaveOptions {
OutputFile = $"output_folder/{filename}.csv",
Format = TextFormat.Csv
};
var converter = new TextConverter(loadOptions, saveOptions);
converter.Convert();
}
将 Excel API 响应转换为 PDF 报告
using Aspose.Cells.LowCode;
using System.Net.Http;
using System.IO;
// Download Excel file from API
using (var client = new HttpClient())
{
byte[] excelData = await client.GetByteArrayAsync("//api.example.com/reports/latest");
File.WriteAllBytes("temp_report.xlsx", excelData);
// Convert to PDF
var loadOptions = new LowCodeLoadOptions { InputFile = "temp_report.xlsx" };
var pdfOptions = new LowCodePdfSaveOptions {
OutputFile = "latest_report.pdf",
EmbedFonts = true
};
var pdfConverter = new PdfConverter(loadOptions, pdfOptions);
pdfConverter.Convert();
// Clean up temp file
File.Delete("temp_report.xlsx");
}
成本效益分析:Aspose.Cells.LowCode 为何值得
节省时间
降低成本
商业利益
结论:立即简化您的 Excel 自动化
问:Aspose.Cells.LowCode 需要安装 Microsoft Excel 吗?
答:不需要,它完全独立,无需任何 Microsoft Office 组件即可运行。
问:我可以在 Azure 或 AWS 等云环境中使用它吗?
答:当然可以!它完全兼容云部署和容器化环境。
问:许可证如何运作?
答:Aspose 提供灵活的许可模式,包括开发者许可证、站点许可证和计量使用选项。
问:我可以转换不同的 Excel 格式(XLS、XLSX 等)吗?
答:是的,该库支持所有主要 Excel 格式之间的转换。
问:它适合大批量处理吗?
答:当然。Aspose.Cells.LowCode 针对性能进行了优化,可以高效处理大量数据。
问:Excel 文件中的宏和公式怎么办?
答:该库在格式转换期间会保留宏,并可以在生成 PDF 或 HTML 等输出格式时评估公式。
关于慧都科技:
慧都科技是⼀家⾏业数字化解决⽅案公司,专注于软件、⽯油与⼯业领域,以深⼊的业务理解和⾏业经验,帮助企业实现智能化转型与持续竞争优势。在软件工程领域,我们提供开发控件、研发管理、代码开发、部署运维等软件开发全链路所需的产品,提供正版授权采购、技术选型、个性化维保等服务,帮助客户实现技术合规、降本增效与风险可控。
慧都科技是Aspose在中国的官方授权代理商,Aspose作为文件格式处理领域的领先技术提供商,通过其强大的工具,助力企业实现文档的高效处理与管理。Aspose支持多种格式(包括但不限于Word、PDF、Excel、PowerPoint、图像、CAD文件等),提供精确查看、便捷编辑、灵活转换等功能,帮助企业轻松应对各类文档处理需求。
下载|体验更多Aspose产品,请咨询,或拨打产品热线:023-68661681
加入Aspose技术交流QQ群(1041253375),与更多小伙伴一起探讨提升开发技能。
本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@wqylolg.cn
文章转载自:慧都网