How to use the xmlbuilder.streamWriter function in xmlbuilder

To help you get started, we’ve selected a few xmlbuilder examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github natergj / excel4node / src / workbook / builder / workbook.ts View on Github external
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));
github natergj / excel4node / src / workbook / builder / wokbookRels.ts View on Github external
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
github natergj / excel4node / src / workbook / builder / styles.ts View on Github external
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);
github intuit / proof / plugins / junit / src / main.ts View on Github external
fileWriteStream.on('open', () => {
      tree.end(
        XMLBuilder.streamWriter(fileWriteStream, {
          pretty: true
        })
      );
      fileWriteStream.on('close', () => {
        resolve();
      });
      fileWriteStream.end();
    });
  });
github natergj / excel4node / src / workbook / builder / rootRels.ts View on Github external
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);
github natergj / excel4node / src / workbook / builder / sharedStrings.ts View on Github external
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')
github natergj / excel4node / src / worksheet / builder / index.ts View on Github external
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,
    })
github natergj / excel4node / src / workbook / builder / contentTypes.ts View on Github external
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) {
github natergj / excel4node / src / worksheet / builder / index.ts View on Github external
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,
  });

xmlbuilder

An XML builder for node.js

MIT
Latest version published 5 years ago

Package Health Score

70 / 100
Full package analysis