xlsxtomd: omit header row (optional)

Signed-off-by: Jared Van Bortel <jared@nomic.ai>
This commit is contained in:
Jared Van Bortel 2024-09-30 16:31:29 -04:00
parent f3a73e87e3
commit cee91fdebe

View File

@ -127,29 +127,14 @@ QString XLSXToMD::toMarkdown(const QString &xlsxFilePath)
continue; continue;
} }
// Assume the first row is the header // Separator row (no header)
int headerRow = firstRow;
// Collect headers
QStringList headers;
for (int col = firstCol; col <= lastCol; ++col) {
QString header = getCellValue(sheet, headerRow, col);
headers << header;
}
// Create Markdown header row
QString headerRowMarkdown = "|" + headers.join("|") + "|";
markdown += headerRowMarkdown + "\n";
// Create Markdown separator row
QStringList separators; QStringList separators;
for (int i = 0; i < headers.size(); ++i) for (int col = firstCol; col <= lastCol; ++col)
separators << "---"; separators << u"---"_s;
QString separatorRow = "|" + separators.join("|") + "|"; markdown += u"|%1|\n"_s.arg(separators.join(u'|'));
markdown += separatorRow + "\n";
// Iterate through data rows (starting from the row after header) // Iterate through data rows
for (int row = headerRow + 1; row <= lastRow; ++row) { for (int row = 0; row <= lastRow; ++row) {
QStringList rowData; QStringList rowData;
for (int col = firstCol; col <= lastCol; ++col) { for (int col = firstCol; col <= lastCol; ++col) {
QString cellText = getCellValue(sheet, row, col); QString cellText = getCellValue(sheet, row, col);