我正在尝试使用LibXL。我可以从工作表中提取数据,但需要一个函数将带有Excel行和列索引的字符串转换为startRow,endRow,startCol,endCol,即
“A1:B3”进入startRow = 0,endRow = 2,startCol = 0,endCol = 1(LibXL使用0基于索引)
我已经尝试了所有我能想到的东西。该库没有任何使用此功能的示例,并且文档非常稀疏。我做错了什么?
这是我的代码:
int main()
{
const char range[] = "B2:C3";
int i, ret, rowFirst=0, rowLast=0, colFirst=0, colLast=0;
BookHandle book;
SheetHandle sheet;
book = xlCreateBook();
ret = xlBookLoad(book, "/home/jason/Downloads/panel.xls");
sheet = xlBookGetSheet(book, 0);
ret = xlSheetGetNamedRange(sheet, &range[0], &rowFirst, &rowLast, &colFirst, &colLast);
printf("ret from xlSheet...Range = %d\n", ret);
printf("%s\n", xlBookErrorMessage(book));
printf("rowLast = %d\n", rowLast);
printf("rowLast = %d\n", rowLast);
printf("colFirst = %d\n", colFirst);
printf("colLast = %d\n", colLast);
return 0;
}
答案 0 :(得分:0)
为此目的使用xlSheetAddrToRowCol()函数:
int rowStart, colStart, rowEnd, colEnd;
int rowRelativeStart, colRelativeStart, rowRelativeEnd, colRelativeEnd;
xlSheetAddrToRowCol(sheet, "B2", &rowStart, &colStart, &rowRelativeStart, &colRelativeStart);
xlSheetAddrToRowCol(sheet, "C3", &rowEnd, &colEnd, &rowRelativeEnd, &colRelativeEnd);