Replies: 4 comments 1 reply
-
I also need this for my company |
Beta Was this translation helpful? Give feedback.
-
Any update on this? Even I'm facing the same issue. |
Beta Was this translation helpful? Give feedback.
-
I'd also be interested. Based on what the AI told me, we cannot set up the label using exceljs… |
Beta Was this translation helpful? Give feedback.
-
I ended up creating an "innersource" javascript library to do this for my company. I was able to reverse engineer what happened when I added my company specific sensitivity labels. Basically Here is the high level function. I did not include the detailed implementation here. /**
* Adds sensitivity label to office document buffer
* @param {Uint8Array} buffer The office document buffer.
* @param {string} [label] The sensitivity label.
* @returns {Promise<Uint8Array>} - The updated office document file buffer with the applied sensitivity label.
*/
export const addSensitivityLabel = async (buffer, label) => {
// Extract the buffer into a zip object
const zip = await JSZip.loadAsync(buffer);
// Add docProps/custom.xml with sensitivity label
zip.file(customFileName, createCustomXml(label));
// Update [Content_types].xml with a reference to the new docProps/custom.xml file
await appendTagToXmlTags(zip, '[Content_Types].xml', 'Types', 'Override', {
'PartName': `/${customFileName}`,
'ContentType': 'application/vnd.openxmlformats-officedocument.custom-properties+xml'
});
// Update _rels/.rels to reference custom XML
await appendTagToXmlTags(zip, '_rels/.rels', 'Relationships', 'Relationship', {
'Type': `${baseSchema}/relationships/custom-properties`,
'Target': customFileName
});
return await zip.generateAsync({ type: 'uint8array' });
} Once I got the details and implementation working, I was easily able to add labels as follows: import { Workbook } from 'exceljs';
import saveAs from 'file-saver';
import { addSensitivityLabel } from '@mycustomlib/office-sensitivity-labels'
// Create an empty workbook with exceljs library
const workbook = new Workbook();
// Write the workbook to a buffer then add the default sensitivity label
const buffer = await addSensitivityLabel(await workbook.xlsx.writeBuffer(), 'MyLabelName');
// Save file
saveAs(new Blob([buffer], { type: 'application/octet-stream' }), 'example.xlsx'); |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
When I open a downloaded file created using exceljs it always as me to label it. Is it possible to label it using exceljs?
Beta Was this translation helpful? Give feedback.
All reactions