Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,7 @@ Thumbs.db

# Ignore built ts files
__tests__/runner/*
lib/**/*
lib/**/*

# IntelliJ IDE project files
.idea/
9 changes: 6 additions & 3 deletions src/converters/xlsx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@ export class XlsxConverter extends HtmlConverter {
let mdContent = "";

for (const sheetName of workbook.SheetNames) {
mdContent += `## ${sheetName}\n`;
let htmlContent = XLSX.utils.sheet_to_html(workbook.Sheets[sheetName]);
mdContent += (await this._convert(htmlContent))?.markdown.trim() + "\n\n";
const sheet = workbook.Sheets[sheetName];
if (sheet["!ref"]) {
mdContent += `## ${sheetName}\n`;
let htmlContent = XLSX.utils.sheet_to_html(sheet);
mdContent += (await this._convert(htmlContent))?.markdown.trim() + "\n\n";
}
}
return { title: workbook?.Props?.Title || "Untitled", markdown: mdContent, text_content: mdContent };
} catch (e) {
Expand Down
Binary file added test/__files/test_empty_sheets.xlsx
Binary file not shown.
13 changes: 13 additions & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,19 @@ describe("MarkItDown Tests", () => {
expect(textContent).toContain(testString);
}
});

it("should convert .xlsx having empty sheets to markdown", async () => {
const markitdown = new MarkItDown();
const result = await markitdown.convert(
path.join(__dirname, "__files/test_empty_sheets.xlsx")
);
expect(result).not.toBeNull();
expect(result).not.toBeUndefined();
const textContent = result?.markdown.replace("\\", "");
for (const testString of XLSX_TEST_STRINGS) {
expect(textContent).toContain(testString);
}
});
});

describe("WAV Converter", () => {
Expand Down