1. 产品
  2.   电子表格
  3.   C++
  4.   Aspose.Cells for C++

Aspose.Cells for C++

 
 

用于生成和导出 Excel 电子表格的 C++ API

使用 C++ API 读取、写入、编辑、渲染、操作、打印和转换 Excel 电子表格文件,无需使用 Microsoft Excel。

Aspose.Cells for C++ 是一个原生 C++ 库,为软件程序员提供了生成、修改、编辑的能力 、操作和转换 Excel 电子表格,而无需使用系统上安装的 Microsoft Office 或 Excel。 Aspose.Cells for C++ 的主要功能之一是它能够读取和写入各种电子表格格式,包括 Microsoft Excel(XLS、XLSX、XLSM、XLSB)、OpenDocument 格式 (ODS)、PDF、HTML、CSV、 还有很多。 这使其成为处理旧文件或与可能不支持最新 Excel 格式的其他系统集成的理想解决方案。

除了基本的电子表格读写功能外,Aspose.Cells for C++ 还融入了广泛的高级功能,例如公式计算、数据验证、应用工作簿的自定义主题颜色、管理 Excel 表格、对行和列进行分组 工作表的编辑、将主题从一个工作簿复制到另一个工作簿、创建和操作数据透视表、图表创建等等。 您可以使用该库在任何支持 C++ 的开发环境(例如 Microsoft Visual Studio)中开发 32 位和 64 位应用程序。

Aspose.Cells for C++ 帮助软件开发人员以最少的精力和成本在自己的应用程序中添加复杂的电子表格功能。 Aspose.Cells for C++ 还提供了将电子表格文档转换为其他支持的文件格式的功能,例如 PDF、XPS、CSV、TSV、ODS、HTML 和图像(PEG、PNG、BMP、TIFF、GIF、EMF、SVG) 文件格式。 这对于创建报告、发票或需要以不可编辑格式与其他人共享的其他文档非常有用。 总体而言,Aspose.Cells for C++ 是一个多功能且功能强大的电子表格处理库,可以帮助 C++ 开发人员轻松地将高级电子表格功能添加到他们的应用程序中。

Previous Next

C++ 版 Aspose.Cells 入门

安装 Aspose.Cells for C++ 的推荐方法是使用 NuGet。 为了顺利安装,请使用以下命令。

通过 NuGet 安装用于 C++ 的 Aspose.Cells

NuGet\Install-Package Aspose.Cells.Cpp -Version 23.1.0 
您也可以直接从 Aspose 产品发布页面下载。

通过 C++ 将 Excel 工作簿转换为 PDF 和其他格式

Aspose.Cells for C++ 支持将 Excel 电子表格文件转换为 C++ 应用程序内各种其他支持的文件格式,只需两行代码。 该库提供了各种流行文件格式的转换,例如 XLSM、XLTX、XLTM、XLAM、PDF、XPS 和图像(PEG、PNG、BMP、TIFF、GIF、EMF、SVG)文件格式。 该库提供了将 Excel 工作簿转换为 PDF 和其他文件格式的各种功能,例如直接使用 IWorkbook 类的 Save 方法、高级 IPdfSaveOptions 类或在文档创建时使用 get 或 set 方法。

通过 .NET API 将 Excel 工作簿转换为 PDF

StringPtr srcDir = new String("..\\Data\\01_SourceDirectory\\");

// Output directory path.
StringPtr outDir = new String("..\\Data\\02_OutputDirectory\\");

// Path of input Excel file
StringPtr sampleConvertExcelWorkbookToPDF = srcDir->StringAppend(new String("sampleConvertExcelWorkbookToPDF.xlsx"));

// Path of output Pdf file
StringPtr outputConvertExcelWorkbookToPDF = outDir->StringAppend(new String("outputConvertExcelWorkbookToPDF_DirectConversion.pdf"));

// Load the sample Excel file.
intrusive_ptr workbook = Factory::CreateIWorkbook(sampleConvertExcelWorkbookToPDF);

// Save the Excel Document in PDF format
workbook->Save(outputConvertExcelWorkbookToPDF, SaveFormat_Pdf);

通过 C++ API 打开和加载不同的文件格式

Aspose.Cells for C++ 使软件开发人员能够保护或取消保护其 .NET 应用程序中的电子表格文档。 该库包含了几个用于保护电子表格文件及其内部数据的重要功能,例如通过应用密码防止其他人访问 Excel 文件中的数据、保护和取消保护工作簿或工作表、添加数字签名等等。该库还支持 防止查看隐藏的工作表、添加、移动、删除或隐藏工作表以及重命名工作表。

通过 .NET API 密码保护或取消保护共享工作簿

Workbook wb = new Workbook();

//Protect the Shared Workbook with Password
wb.ProtectSharedWorkbook("1234");

//Uncomment this line to Unprotect the Shared Workbook
//wb.UnprotectSharedWorkbook("1234");

//Save the output Excel file
wb.Save("outputProtectSharedWorkbook.xlsx");

通过 C++ API 在电子表格中创建和管理图表

Aspose.Cells for C++ 允许计算机程序员使用 C++ 命令在 Excel 电子表格文件中插入和管理图表。 该库允许开发人员像 Microsoft Excel 一样以图表形式可视化信息。 它为 MS-Excel 和其他领先的电子表格应用程序支持的一些常见图表类型提供支持,例如金字塔图、折线图、气泡图等。 开发人员还可以将 Excel 图表呈现为图像和 PDF 格式,而无需任何其他工具或应用程序。 该库还允许读取和处理 Microsoft Excel 2016 图表,这些图表在 Microsoft Excel 2013 或之前版本中不可用。

通过 C++ API 将金字塔图添加到 Excel 工作表

// Output directory path
StringPtr outDir = new String("..\\Data\\02_OutputDirectory\\");

// Path of output excel file
StringPtr outputChartTypePyramid = outDir->StringAppend(new String("outputChartTypePyramid.xlsx"));

// Create a new workbook
intrusive_ptr workbook = Factory::CreateIWorkbook();

// Get first worksheet which is created by default
intrusive_ptr worksheet = workbook->GetIWorksheets()->GetObjectByIndex(0);

// Adding sample values to cells
worksheet->GetICells()->GetObjectByIndex(new String("A1"))->PutValue(50);
worksheet->GetICells()->GetObjectByIndex(new String("A2"))->PutValue(100);
worksheet->GetICells()->GetObjectByIndex(new String("A3"))->PutValue(150);
worksheet->GetICells()->GetObjectByIndex(new String("B1"))->PutValue(4);
worksheet->GetICells()->GetObjectByIndex(new String("B2"))->PutValue(20);
worksheet->GetICells()->GetObjectByIndex(new String("B3"))->PutValue(50);

// Adding a chart to the worksheet
int chartIndex = worksheet->GetICharts()->Add(Aspose::Cells::Charts::ChartType::ChartType_Pyramid, 5, 0, 20, 8);

// Accessing the instance of the newly added chart
intrusive_ptr chart = worksheet->GetICharts()->GetObjectByIndex(chartIndex);

// Adding SeriesCollection (chart data source) to the chart ranging from "A1" cell to "B3"
chart->GetNISeries()->Add(new String("A1:B3"), true);

// Saving the Excel file
workbook->Save(outputChartTypePyramid);

通过 C++ API 添加超链接并操作 Excel 文件中的数据

Aspose.Cells for C++ 包含了几个使用 C++ API 处理 Excel 电子表格文件内数据的重要功能。 该库允许访问电子表格单元格中的数据,从单元格、行或列添加和检索数据,轻松插入单元格的超链接。 还可以在工作表中应用条件格式并在 Excel 工作簿中创建命名范围。 该库还方便开发人员搜索数据、操作工作簿中的命名范围、应用样式和格式、先例或依赖项等。

通过 C++ API 添加超链接到 Excel 单元格

/Path of output excel file
StringPtr outputAddHyperlinksToTheCells = outPath->StringAppend(new String("outputAddHyperlinksToTheCells.xlsx"));

//Create a new workbook
intrusive_ptr workbook = Factory::CreateIWorkbook();

//Get the first worksheet
intrusive_ptr wsc = workbook->GetIWorksheets();
intrusive_ptr ws = wsc->GetObjectByIndex(0);

//Add hyperlink in cell C7 and make use of its various methods
intrusive_ptr hypLnks = ws->GetIHyperlinks();
int idx = hypLnks->Add(new String("C7"), 1, 1, new String("http://www.aspose.com/"));
intrusive_ptr lnk = hypLnks->GetObjectByIndex(idx);
lnk->SetTextToDisplay(new String("Aspose"));
lnk->SetScreenTip(new String("Link to Aspose Website"));

//Save the workbook
workbook->Save(outputAddHyperlinksToTheCells);
 中国人