I need to read an Excel file with many merged cells. Suppose the first column contains the 'Category' value and the second column contains the 'sub_category' value. The problem is that each category cell might be a merged cell with multiple sub_categories in the second column. I need to know the number of rows witch this merged cell occupies. My chart is something like this:
Similar questions have already been asked but in different languages:
QString category = "";
QString sub_category = "";
auto excel = new QAxObject("Excel.Application");
auto workbooks = excel->querySubObject("Workbooks");
auto workbook = workbooks->querySubObject("Open(const QString&)" ,"C:\\Users\\Orkideh\\Documents\\build-MyApp-Desktop_Qt_5_12_9_MSVC2017_64bit-Debug\\Book1.xlsx");
auto sheets = workbook->querySubObject("Worksheets");
auto sheet = sheets->querySubObject("Item(int)", 1);
// Read the rows 2..150
for (int r = 2; (r <= 150); ++r)
{
auto cCell = sheet->querySubObject("Cells(int,int)",r,1);
category = cCell->dynamicCall("Value()").toString().simplified();
// if each row in the excel file had only 1 category and 1 sub-category,
// I could use the below code to get sub_category:
// cCell = sheet->querySubObject("Cells(int,int)",r, 2);
// sub_category = cCell->dynamicCall("Value()").toString().simplified();
// But in fact, the cell with category value might be a merged cell with
// unknown number of rows.
// I need to know the number of rows that this merged cell occupies to connect
// each sub_category to its own category.
}