Fix Excel export XML order and gate time adjustments on close
This commit is contained in:
parent
be9816a3a8
commit
9d569d987d
4 changed files with 379 additions and 254 deletions
|
|
@ -27,10 +27,8 @@ function escapeXml(value: string): string {
|
|||
.replace(/</g, "<")
|
||||
.replace(/>/g, ">")
|
||||
.replace(/"/g, """)
|
||||
.replace(/\u0008/g, "")
|
||||
.replace(/\u000B/g, "")
|
||||
.replace(/\u000C/g, "")
|
||||
.replace(/\u0000/g, "")
|
||||
// remove invalid control characters (XML 1.0)
|
||||
.replace(/[\x00-\x08\x0B\x0C\x0E-\x1F]/g, "")
|
||||
}
|
||||
|
||||
function columnRef(index: number): string {
|
||||
|
|
@ -60,7 +58,7 @@ function formatCell(value: unknown, colIndex: number, rowNumber: number, styleIn
|
|||
}
|
||||
|
||||
if (typeof value === "boolean") {
|
||||
return `<c r="${ref}"${styleAttr}><v>${value ? 1 : 0}</v></c>`
|
||||
return `<c r="${ref}"${styleAttr} t="b"><v>${value ? 1 : 0}</v></c>`
|
||||
}
|
||||
|
||||
let text: string
|
||||
|
|
@ -123,17 +121,24 @@ function buildWorksheetXml(config: WorksheetConfig, styles: WorksheetStyles): st
|
|||
sheetViews = `<sheetViews><sheetView workbookViewId="0">${pane}</sheetView></sheetViews>`
|
||||
}
|
||||
|
||||
const usedRangeColumn = config.headers.length > 0 ? columnRef(config.headers.length - 1) : "A"
|
||||
const dimensionXml =
|
||||
config.headers.length > 0 && totalRows > 0
|
||||
? `<dimension ref="A1:${usedRangeColumn}${totalRows}"/>`
|
||||
: ""
|
||||
|
||||
const autoFilter =
|
||||
config.autoFilter && config.headers.length > 0 && totalRows > 1
|
||||
? `<autoFilter ref="A1:${columnRef(config.headers.length - 1)}${totalRows}"/>`
|
||||
? `<autoFilter ref="A1:${usedRangeColumn}${totalRows}"/>`
|
||||
: ""
|
||||
|
||||
return [
|
||||
XML_DECLARATION,
|
||||
'<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">',
|
||||
dimensionXml,
|
||||
sheetViews,
|
||||
colsXml,
|
||||
' <sheetFormatPr defaultRowHeight="15"/>',
|
||||
colsXml,
|
||||
" <sheetData>",
|
||||
rows.map((row) => ` ${row}`).join("\n"),
|
||||
" </sheetData>",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue