This commit is contained in:
Radhakrishnan Pachyappan 2026-06-27 13:41:45 +05:30 committed by GitHub
commit 95225f7751
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 142 additions and 7 deletions

View file

@ -46,10 +46,29 @@ export const properties = {
"xml",
"zabw",
],
calc: [
"csv",
"dbf",
"dif",
"fods",
"ods",
"ots",
"sxc",
"stc",
"slk",
"tab",
"tsv",
"xls",
"xlsb",
"xlsm",
"xlsx",
"xlt",
"xltm",
"xltx",
],
},
to: {
text: [
"csv",
"doc",
"docm",
"docx",
@ -72,12 +91,17 @@ export const properties = {
"xhtml",
"xml",
],
calc: ["csv", "fods", "html", "ods", "ots", "xls", "xlsx"],
},
};
type FileCategories = "text" | "calc";
const filters: Record<FileCategories, Record<string, string>> = {
// Separate input and output filter maps because some formats (e.g. csv) are
// readable by LibreOffice Writer but cannot be exported by it — Writer has no
// CSV export filter. Using a unified map caused "no export filter found" when
// converting any Writer document to CSV (issue #561).
const inputFilters: Record<FileCategories, Record<string, string>> = {
text: {
"602": "T602Document",
abw: "AbiWord",
@ -120,16 +144,71 @@ const filters: Record<FileCategories, Record<string, string>> = {
xml: "OpenDocument Text Flat XML",
zabw: "AbiWord",
},
calc: {},
calc: {
csv: "Text - txt - csv (StarCalc)",
dbf: "dBase",
dif: "DIF",
fods: "OpenDocument Spreadsheet Flat XML",
html: "HTML (StarCalc)",
ods: "calc8",
ots: "calc8_template",
sxc: "StarOffice XML (Calc)",
stc: "calc_StarOffice_XML_Calc_Template",
slk: "SYLK",
tab: "Text - txt - csv (StarCalc)",
tsv: "Text - txt - csv (StarCalc)",
xls: "MS Excel 97",
xlsb: "Calc MS Excel 2007 Binary",
xlsm: "Calc MS Excel 2007 VBA XML",
xlsx: "Calc MS Excel 2007 XML",
xlt: "MS Excel 97 Vorlage/Template",
xltm: "Calc MS Excel 2007 VBA XML Template",
xltx: "Calc MS Excel 2007 XML Template",
},
};
const outputFilters: Record<FileCategories, Record<string, string>> = {
text: {
// csv intentionally absent: LibreOffice Writer has no CSV export filter
doc: "MS Word 97",
docm: "MS Word 2007 XML VBA",
docx: "MS Word 2007 XML",
dot: "MS Word 97 Vorlage",
dotx: "MS Word 2007 XML Template",
dotm: "MS Word 2007 XML Template",
epub: "EPUB",
fodt: "OpenDocument Text Flat XML",
htm: "HTML (StarWriter)",
html: "HTML (StarWriter)",
odt: "writer8",
ott: "writer8_template",
rtf: "Rich Text Format",
tab: "Text",
tsv: "Text",
txt: "Text",
wps: "MS Word 97",
wpt: "MS Word 97 Vorlage",
xhtml: "HTML (StarWriter)",
xml: "OpenDocument Text Flat XML",
},
calc: {
csv: "Text - txt - csv (StarCalc)",
fods: "OpenDocument Spreadsheet Flat XML",
html: "HTML (StarCalc)",
ods: "calc8",
ots: "calc8_template",
xls: "MS Excel 97",
xlsx: "Calc MS Excel 2007 XML",
},
};
const getFilters = (fileType: string, converto: string) => {
if (converto === "pdf") {
return [null, null];
} else if (fileType in filters.text && converto in filters.text) {
return [filters.text[fileType], filters.text[converto]];
} else if (fileType in filters.calc && converto in filters.calc) {
return [filters.calc[fileType], filters.calc[converto]];
} else if (fileType in inputFilters.text && converto in outputFilters.text) {
return [inputFilters.text[fileType], outputFilters.text[converto]];
} else if (fileType in inputFilters.calc && converto in outputFilters.calc) {
return [inputFilters.calc[fileType], outputFilters.calc[converto]];
}
return [null, null];
};

View file

@ -166,3 +166,59 @@ test("logs stderr on exec error as well", async () => {
// The callback still provided stderr; your implementation logs it before settling
expect(errors).toContain("stderr: EPIPE");
});
// --- calc (spreadsheet) category --------------------------------------------
test("uses Calc infilter and outfilter for xlsx -> csv (regression for issue #561)", async () => {
await convert("in.xlsx", "xlsx", "csv", "out/out.csv", undefined, mockExecFile);
const { args } = requireDefined(calls[0], "Expected at least one execFile call");
expect(args).toEqual([
"--headless",
"--infilter=Calc MS Excel 2007 XML",
"--convert-to",
"csv:Text - txt - csv (StarCalc)",
"--outdir",
"out",
"in.xlsx",
]);
});
test("uses Calc infilter and outfilter for csv -> xlsx", async () => {
await convert("in.csv", "csv", "xlsx", "out/out.xlsx", undefined, mockExecFile);
const { args } = requireDefined(calls[0], "Expected at least one execFile call");
expect(args).toEqual([
"--headless",
"--infilter=Text - txt - csv (StarCalc)",
"--convert-to",
"xlsx:Calc MS Excel 2007 XML",
"--outdir",
"out",
"in.csv",
]);
});
test("uses Calc infilter and outfilter for ods -> xlsx", async () => {
await convert("in.ods", "ods", "xlsx", "out/out.xlsx", undefined, mockExecFile);
const { args } = requireDefined(calls[0], "Expected at least one execFile call");
expect(args).toEqual([
"--headless",
"--infilter=calc8",
"--convert-to",
"xlsx:Calc MS Excel 2007 XML",
"--outdir",
"out",
"in.ods",
]);
});
test("pdf -> csv produces no filters (cross-category: not supported via LibreOffice Writer)", async () => {
await convert("in.pdf", "pdf", "csv", "out/out.csv", undefined, mockExecFile);
const { args } = requireDefined(calls[0], "Expected at least one execFile call");
// pdf is Writer-category; csv output requires Calc — no valid cross-category
// filter exists, so soffice is invoked without explicit filters and will fail
// gracefully. The properties list no longer exposes this combination.
expect(args).toEqual(["--headless", "--convert-to", "csv", "--outdir", "out", "in.pdf"]);
});