#include <iostream>
#include "ExcelReader.h"

int main() {
    try {
        // 读取 Excel 文件
        ExcelReader reader("example.xlsx");

        // 获取并打印所有工作表的名称
        std::vector<std::string> sheetNames = reader.getSheetNames();
        std::cout << "Available Sheets: " << std::endl;
        for (const auto& sheetName : sheetNames) {
            std::cout << sheetName << std::endl;
        }

        // 读取并打印第一个工作表的数据
        if (!sheetNames.empty()) {
            std::cout << "\nReading data from sheet: " << sheetNames[0] << std::endl;
            auto data = reader.readSheetData(sheetNames[0]);

            // 打印数据
            for (const auto& row : data) {
                for (const auto& cell : row) {
                    std::cout << cell << "\t";
                }
                std::cout << std::endl;
            }
        }

        // 写入新数据
        reader.writeCellData(sheetNames[0], 2, 2, "New Data");

        // 设置单元格数字格式
        reader.setCellNumberFormat(sheetNames[0], 1, 1, "#,##0.00");

        // 合并单元格
        reader.mergeCells(sheetNames[0], 1, 1, 2, 2);

        // 保存修改后的文件
        reader.saveToFile("modified_example.xlsx");

    } catch (const std::exception& e) {
        std::cerr << "An error occurred: " << e.what() << std::endl;
    }

    return 0;
}
