使用C++控制工作表标签栏的方法

可能的使用场景

当需要调整Excel工作表标签栏的显示时,你需要知道如何控制标签栏,例如隐藏或显示标签栏、改变标签栏宽度、指定第一个可见标签等。Aspose.Cells支持这些功能。Aspose.Cells提供以下属性和方法帮助你实现目标。

** 使用Aspose.Cells for C++控制工作表标签栏的方法**

此示例演示如何:

  1. 创建一个工作簿。
  2. 在第一个工作表中的单元格中添加数据。
  3. 显示工作表标签并设置标签栏的宽度。
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;

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

    // Create a Workbook object
    Workbook workbook;

    // Obtain the reference to the newly added worksheet
    Worksheet ws = workbook.GetWorksheets().Get(0);
    Cells cells = ws.GetCells();

    // Setting the value to the cells
    Cell cell = cells.Get(u"A1");
    cell.PutValue(u"Fruit");
    cell = cells.Get(u"B1");
    cell.PutValue(u"Count");
    cell = cells.Get(u"C1");
    cell.PutValue(u"Price");

    cell = cells.Get(u"A2");
    cell.PutValue(u"Apple");
    cell = cells.Get(u"A3");
    cell.PutValue(u"Mango");
    cell = cells.Get(u"A4");
    cell.PutValue(u"Blackberry");
    cell = cells.Get(u"A5");
    cell.PutValue(u"Cherry");

    // Display the sheet tab and set the width of the tab bar
    workbook.GetSettings().SetShowTabs(true);
    workbook.GetSettings().SetSheetTabBarWidth(150);

    // Save the workbook
    workbook.Save(u"out.xlsx");

    std::cout << "Workbook saved successfully!" << std::endl;

    Aspose::Cells::Cleanup();
}

结果文件预览: