Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default function addWorkbookXml(builder: IWorkbookBuilder) {
const { wb, xlsx } = builder;
const dataStream = getDataStream();
const writer = xmlbuilder.streamWriter(dataStream);
const xml = xmlbuilder.create('workbook', {
version: '1.0',
encoding: 'UTF-8',
standalone: true,
});
xml.att('mc:Ignorable', 'x15');
xml.att('xmlns', 'http://schemas.openxmlformats.org/spreadsheetml/2006/main');
xml.att('xmlns:mc', 'http://schemas.openxmlformats.org/markup-compatibility/2006');
xml.att('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships');
xml.att('xmlns:x15', 'http://schemas.microsoft.com/office/spreadsheetml/2010/11/main');
// workbookPr (§18.2.28)
const workbookPrEle = xml.ele('workbookPr');
if (wb.workbookProperties.allowRefreshQuery) {
workbookPrEle.att('allowRefreshQuery', boolToInt(wb.workbookProperties.allowRefreshQuery));
export default function addWorkbookXml(builder: IWorkbookBuilder) {
const { wb, xlsx } = builder;
const dataStream = getDataStream();
const writer = xmlbuilder.streamWriter(dataStream);
const xml = xmlbuilder
.create('Relationships', {
version: '1.0',
encoding: 'UTF-8',
standalone: true,
})
.att('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships');
xml
.ele('Relationship')
.att('Id', `rId${wb.sheets.size + 1}`)
.att('Target', 'sharedStrings.xml')
.att('Type', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings');
// xml
export default function addContentTypes(builder: IWorkbookBuilder) {
const { wb, xlsx } = builder;
const dataStream = getDataStream();
const writer = xmlbuilder.streamWriter(dataStream);
const xml = xmlbuilder
.create('styleSheet', {
version: '1.0',
encoding: 'UTF-8',
standalone: true,
})
.att('mc:Ignorable', 'x14ac')
.att('xmlns', 'http://schemas.openxmlformats.org/spreadsheetml/2006/main')
.att('xmlns:mc', 'http://schemas.openxmlformats.org/markup-compatibility/2006')
.att('xmlns:x14ac', 'http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac');
if (wb.styleData.numFmts.length > 0) {
const nfXML = xml.ele('numFmts').att('count', wb.styleData.numFmts.length);
wb.styleData.numFmts.forEach(nf => {
nf.addToXMLele(nfXML);
fileWriteStream.on('open', () => {
tree.end(
XMLBuilder.streamWriter(fileWriteStream, {
pretty: true
})
);
fileWriteStream.on('close', () => {
resolve();
});
fileWriteStream.end();
});
});
export default function addContentTypes(builder: IWorkbookBuilder) {
const { xlsx } = builder;
const dataStream = getDataStream();
const writer = xmlbuilder.streamWriter(dataStream);
const xml = xmlbuilder
.create('Relationships', {
version: '1.0',
encoding: 'UTF-8',
standalone: true,
})
.att('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships');
xml
.ele('Relationship')
.att('Id', 'rId1')
.att('Type', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument')
.att('Target', 'xl/workbook.xml');
xlsx.folder('_rels').file('.rels', dataStream);
export default function addSharedStrings(builder: IWorkbookBuilder) {
const { wb, xlsx } = builder;
const dataStream = getDataStream();
const writer = xmlbuilder.streamWriter(dataStream);
const xml = xmlbuilder
.create('sst', {
version: '1.0',
encoding: 'UTF-8',
standalone: true,
})
.att('count', wb.sharedStrings.size)
.att('uniqueCount', wb.sharedStrings.size)
.att('xmlns', 'http://schemas.openxmlformats.org/spreadsheetml/2006/main');
for ( const str of wb.sharedStrings.keys() ) {
const val = JSON.parse(str);
if (typeof val === 'string') {
xml
.ele('si')
export function addWorksheetFile(builder: IWorkbookBuilder, ws: Worksheet) {
const dataStream = getDataStream();
const writer = xmlbuilder.streamWriter(dataStream);
builder.xlsx
.folder('xl')
.folder('worksheets')
.file(`sheet${ws.sheetId}.xml`, dataStream);
dataStream.on('error', err => {
throw err;
});
const xml = xmlbuilder
.create('worksheet', {
version: '1.0',
encoding: 'UTF-8',
standalone: true,
})
export default function addContentTypes(builder: IWorkbookBuilder) {
const { wb, xlsx } = builder;
const contentTypesAdded = [];
const extensionsAdded = [];
const dataStream = getDataStream();
const writer = xmlbuilder.streamWriter(dataStream);
xlsx.file('[Content_Types].xml', dataStream);
dataStream.on('error', e => {
throw e;
});
const xml = xmlbuilder
.create('Types', {
version: '1.0',
encoding: 'UTF-8',
standalone: true,
})
.att('xmlns', 'http://schemas.openxmlformats.org/package/2006/content-types');
wb.sheets.forEach((ws: Worksheet) => {
if (ws.drawingCollection.length > 0) {
export function addWorksheetRelsFile(builder: IWorkbookBuilder, ws: Worksheet) {
ws.wb.logger.debug(`adding worksheet rels file: ${ws.name}`);
const dataStream = getDataStream();
const writer = xmlbuilder.streamWriter(dataStream);
builder.xlsx
.folder('xl')
.folder('worksheets')
.folder('_rels')
.file(`sheet${ws.sheetId}.xml.rels`, dataStream);
dataStream.on('error', err => {
throw err;
});
const xml = xmlbuilder.create('Relationships', {
version: '1.0',
encoding: 'UTF-8',
standalone: true,
});