用C++在保存为HTML时启用CSS自定义属性
Contents
[
Hide
]
可能的使用场景
当你将Excel文件保存为HTML时,对于同一基础64图片出现多次的场景,使用自定义属性后只需保存一次图片数据,从而提升生成HTML的性能。请在保存为HTML时使用HtmlSaveOptions.GetEnableCssCustomProperties()属性并将其设置为true。
在保存为HTML时启用CSS自定义属性
以下示例代码展示了HtmlSaveOptions.GetEnableCssCustomProperties()属性的用法。截图显示了当未将此属性设置为true时的效果。请下载此代码中使用的样本Excel文件以及它生成的输出HTML作为参考。
示例代码
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
int main()
{
Aspose::Cells::Startup();
// Source directory path
U16String srcDir(u"..\\Data\\01_SourceDirectory\\");
// Output directory path
U16String outDir(u"..\\Data\\02_OutputDirectory\\");
// Load sample workbook
Workbook wb(srcDir + u"sampleEnableCssCustomProperties.xlsx");
// Create HtmlSaveOptions object
HtmlSaveOptions opts;
// Set ExportImagesAsBase64 to true
opts.SetExportImagesAsBase64(true);
// Enable EnableCssCustomProperties
opts.SetEnableCssCustomProperties(true);
// Save the workbook in HTML format
wb.Save(outDir + u"outputEnableCssCustomProperties.html", opts);
std::cout << "Workbook saved successfully with CSS custom properties enabled!" << std::endl;
Aspose::Cells::Cleanup();
}