没有找到合适的产品?
联系客服协助选型:023-68661681
提供3000多款全球软件/控件产品
针对软件研发的各个阶段提供专业培训与技术咨询
根据客户需求提供定制化的软件开发服务
全球知名设计软件,显著提升设计质量
打造以经营为中心,实现生产过程透明化管理
帮助企业合理产能分配,提高资源利用率
快速打造数字化生产线,实现全流程追溯
生产过程精准追溯,满足企业合规要求
以六西格玛为理论基础,实现产品质量全数字化管理
通过大屏电子看板,实现车间透明化管理
对设备进行全生命周期管理,提高设备综合利用率
实现设备数据的实时采集与监控
利用数字化技术提升油气勘探的效率和成功率
钻井计划优化、实时监控和风险评估
提供业务洞察与决策支持实现数据驱动决策
翻译|使用教程|编辑:李显亮|2020-05-18 10:02:17.277|阅读 776 次
概述:Aspose.Cells for C ++是本机C ++库,可让您创建,读取,解析和转换电子表格文档,而无需Microsoft Excel。在本文中,我们将介绍从头开始创建Excel XLS / XLSX文件的以下功能。
# 界面/图表报表/文档/IDE等千款热门软控件火热销售中 >>
Aspose.Cells for C ++是本机C ++库,可让您创建,读取,解析和转换电子表格文档,而无需Microsoft Excel。它提供了一套完整的Excel自动化功能,可用于生成和操作XLS / XLSX电子表格。
在本文中,我们将介绍从头开始创建Excel XLS / XLSX文件的以下功能。
如果你还没有使用过Aspose.Cells for C ++,可以点击此处下载最新版体验。
一个工作簿由一个或多个工作表组成,每个工作表都包含行和列形式的数据。因此,为了创建Excel电子表格,您需要先创建一个工作簿,然后在其中添加工作表。以下是使用Aspose.Cells for C ++创建Excel文件的步骤。
下面的代码示例演示如何使用C ++创建Excel XLSX文件。
/*create a new workbook*/ intrusive_ptrwb = Factory::CreateIWorkbook(); /*get the first worksheet*/ intrusive_ptrwsc = wb->GetIWorksheets(); intrusive_ptrws = wsc->GetObjectByIndex(0); /*get cell(0,0)*/ intrusive_ptrcells = ws->GetICells(); intrusive_ptrcell = cells->GetObjectByIndex(0, 0); /*write "Hello World" to cell(0,0) of the first sheet*/ intrusive_ptrstr = new String("Hello World!"); cell->PutValue(str); /*save this workbook to resultFile folder*/ wb->Save(resultPath->StringAppend(new String("workbook.xlsx")));
Excel工作簿
以下是我们刚刚创建的Excel工作簿的屏幕截图。
在Excel工作簿中设置公式是一项出色的功能,可以对数据执行计算。它使有效高效地对数据执行复杂的计算变得相当容易。以下是在Excel工作表中设置和计算公式的步骤。
下面的代码示例演示如何使用C ++在Excel XLSX工作簿中添加和计算公式。
//Create a new workbook intrusive_ptrwb = Factory::CreateIWorkbook(); //Get first worksheet which is created by default intrusive_ptrws = wb->GetIWorksheets()->GetObjectByIndex(0); //Adding a value to "A1" cell intrusive_ptrcell = ws->GetICells()->GetObjectByIndex(new String("A1")); cell->PutValue(5); //Adding a value to "A2" cell cell = ws->GetICells()->GetObjectByIndex(new String("A2")); cell->PutValue(15); //Adding a value to "A3" cell cell = ws->GetICells()->GetObjectByIndex(new String("A3")); cell->PutValue(25); //Adding SUM formula to "A4" cell cell = ws->GetICells()->GetObjectByIndex(new String("A4")); cell->SetFormula(new String("=SUM(A1:A3)")); //Calculating the results of formulas wb->CalculateFormula(); //Get the calculated value of the cell "A4" and print it on console cell = ws->GetICells()->GetObjectByIndex(new String("A4")); StringPtr sCalcuInfo = new String(L"Calculated Value of Cell A4: "); Console::WriteLine(sCalcuInfo->StringAppend(cell->GetStringValue()));
Excel工作表中的表用于组织位于一系列单元格中的一组数据。表格还可以帮助您维护工作表中的不同类型的列表。以下是在Excel工作表中创建表的步骤。
下面的代码示例演示如何使用C ++在Excel XLSX文件中创建表。
// Instantiate a Workbook object intrusive_ptrworkbook = Factory::CreateIWorkbook(); // Obtaining the reference of the default(first) worksheet intrusive_ptrworksheet = workbook->GetIWorksheets()->GetObjectByIndex(0); // Obtaining Worksheet's cells collection intrusive_ptrcells = worksheet->GetICells(); // Setting the value to the cells cells->GetObjectByIndex(new String("A1"))->PutValue("Employee"); cells->GetObjectByIndex(new String("B1"))->PutValue("Quarter"); cells->GetObjectByIndex(new String("C1"))->PutValue("Product"); cells->GetObjectByIndex(new String("D1"))->PutValue("Continent"); cells->GetObjectByIndex(new String("E1"))->PutValue("Country"); cells->GetObjectByIndex(new String("F1"))->PutValue("Sale"); cells->GetObjectByIndex(new String("A2"))->PutValue("David"); cells->GetObjectByIndex(new String("A3"))->PutValue("David"); cells->GetObjectByIndex(new String("A4"))->PutValue("David"); cells->GetObjectByIndex(new String("A5"))->PutValue("David"); cells->GetObjectByIndex(new String("A6"))->PutValue("James"); cells->GetObjectByIndex(new String("B2"))->PutValue(1); cells->GetObjectByIndex(new String("B3"))->PutValue(2); cells->GetObjectByIndex(new String("B4"))->PutValue(3); cells->GetObjectByIndex(new String("B5"))->PutValue(4); cells->GetObjectByIndex(new String("B6"))->PutValue(1); cells->GetObjectByIndex(new String("C2"))->PutValue("Maxilaku"); cells->GetObjectByIndex(new String("C3"))->PutValue("Maxilaku"); cells->GetObjectByIndex(new String("C4"))->PutValue("Chai"); cells->GetObjectByIndex(new String("C5"))->PutValue("Maxilaku"); cells->GetObjectByIndex(new String("C6"))->PutValue("Chang"); cells->GetObjectByIndex(new String("D2"))->PutValue("Asia"); cells->GetObjectByIndex(new String("D3"))->PutValue("Asia"); cells->GetObjectByIndex(new String("D4"))->PutValue("Asia"); cells->GetObjectByIndex(new String("D5"))->PutValue("Asia"); cells->GetObjectByIndex(new String("D6"))->PutValue("Europe"); cells->GetObjectByIndex(new String("E2"))->PutValue("China"); cells->GetObjectByIndex(new String("E3"))->PutValue("India"); cells->GetObjectByIndex(new String("E4"))->PutValue("Korea"); cells->GetObjectByIndex(new String("E5"))->PutValue("India"); cells->GetObjectByIndex(new String("E6"))->PutValue("France"); cells->GetObjectByIndex(new String("F2"))->PutValue(2000); cells->GetObjectByIndex(new String("F3"))->PutValue(500); cells->GetObjectByIndex(new String("F4"))->PutValue(1200); cells->GetObjectByIndex(new String("F5"))->PutValue(1500); cells->GetObjectByIndex(new String("F6"))->PutValue(500); // Adding a new List Object to the worksheet worksheet->GetIListObjects()->Add(new String("A1"), new String("F6"), true); intrusive_ptrlistObject = worksheet->GetIListObjects()->GetObjectByIndex(0); // Adding Default Style to the table listObject->SetTableStyleType(TableStyleType_TableStyleMedium10); // Show Total listObject->SetShowTotals(true); // Saving the Excel file workbook->Save(resultPath->StringAppend(new String("Excel_Table.xlsx")));
带表的Excel工作簿
Excel电子表格中的图表用于使用不同类型的图形对象来可视化数据。它们使我们可以快速了解和理解数据,尤其是在数据量巨大时。C ++的Aspose.Cells支持各种图表,包括森伯斯特,树形图,直方图,金字塔,气泡,折线等。以下是使用Aspose.Cells for C ++在Excel工作簿中创建图表的步骤。
下面的代码示例演示如何使用C ++在Excel XLSX文件中创建图表。
// Path of output excel file StringPtr outputChartTypePyramid = resultPath->StringAppend(new String("Exce_Pyramid_Chart.xlsx")); // Create a new workbook intrusive_ptrworkbook = Factory::CreateIWorkbook(); // Get first worksheet which is created by default intrusive_ptrworksheet = 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_ptrchart = 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);
带有图表的Excel工作簿
本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@wqylolg.cn
可视化项目时间线对于有效规划和跟踪至关重要。在本篇博文中,您将学习如何使用 C# 在 Excel 中创建甘特图。只需几行代码,即可自动生成动态、美观的甘特图。
本文将为大家介绍DevExpress XAF如何将.NET Aspire集成到Blazor项目中,欢迎下载最新版组件体验!
在线协同文档编辑器ONLYOFFICE现已支持阿里通义千问( Qwen),带来先进的 AI 功能,实现更智能的文档编辑。本指南将向您展示如何将 Qwen 连接到 ONLYOFFICE,并充分利用其功能。
服务电话
重庆/ 023-68661681
华东/ 13452821722
华南/ 18100878085
华北/ 17347785263
客户支持
技术支持咨询服务
服务热线:400-700-1020
邮箱:sales@wqylolg.cn
关注我们
地址 : 重庆市九龙坡区火炬大道69号6幢