diff --git a/.gitignore b/.gitignore index e46cfd3..4d37773 100644 --- a/.gitignore +++ b/.gitignore @@ -95,4 +95,7 @@ Thumbs.db # Ignore built ts files __tests__/runner/* -lib/**/* \ No newline at end of file +lib/**/* + +# IntelliJ IDE project files +.idea/ \ No newline at end of file diff --git a/src/converters/xlsx.ts b/src/converters/xlsx.ts index 5484524..b844e78 100644 --- a/src/converters/xlsx.ts +++ b/src/converters/xlsx.ts @@ -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) { diff --git a/test/__files/test_empty_sheets.xlsx b/test/__files/test_empty_sheets.xlsx new file mode 100755 index 0000000..eb456a4 Binary files /dev/null and b/test/__files/test_empty_sheets.xlsx differ diff --git a/test/index.test.ts b/test/index.test.ts index ada5df8..92818d4 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -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", () => {