使用C++将Excel转换为带提示的HTML

将 Excel 转换为带有工具提示的 HTML

有时生成的HTML中文本会被截断,你希望在悬停事件中显示完整的文本作为提示。Aspose.Cells支持这一点,提供了HtmlSaveOptions.GetAddTooltipText()属性。将HtmlSaveOptions.GetAddTooltipText()属性设置为true将会在生成的HTML中添加完整文本作为提示。

以下图片显示了生成的 HTML 文件中的工具提示。

todo:image_alt_text

以下代码示例加载源Excel文件并生成带有提示的输出HTML文件

示例代码

#include <iostream>
#include "Aspose.Cells.h"
#include "Aspose.Cells/HtmlSaveOptions.h"

using namespace Aspose::Cells;

int main()
{
    Aspose::Cells::Startup();

    // For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C

    // Source directory path
    U16String sourceDir(u"..\\Data\\01_SourceDirectory\\");

    // Output directory path
    U16String outputDir(u"..\\Data\\02_OutputDirectory\\");

    // Open the template file
    Workbook workbook(sourceDir + u"AddTooltipToHtmlSample.xlsx");

    // Setup HTML save options
    HtmlSaveOptions options;
    options.SetAddTooltipText(true);  // Enable tooltip text in output

    // Save as HTML
    workbook.Save(outputDir + u"AddTooltipToHtmlSample_out.html", options);

    std::cout << "Workbook saved with tooltip text added!" << std::endl;

    Aspose::Cells::Cleanup();
}