-
-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for charts getting data from embedded excel sheets (rather than 'standard' charts) #102
Comments
Hi @MP70! Can I help you on this? Please provide an example pptx file, I'm always interested in new varieties :) |
Sorry! As attached. So I think I have a solution but it is super super involved and therefore I'm not sure if it's best inside the library or not. We have two options; Either are quite involved and potentially fragile. |
Example to get the data I am doing this ATM for (let element of elements) {
let refElements = element.getElementsByTagName("c:numRef");
if (refElements.length > 0) {
let fElement = refElements[0].getElementsByTagName("c:f");
if (fElement.length > 0) {
let excelEmbedInfo = fElement[0].textContent;
let extractedData = await this.extractExcelData(excelEmbedInfo, zip);
data = data.concat(extractedData);
} else {
let valueElements = refElements[0].getElementsByTagName("c:v");
let values = Array.from(valueElements, elem => parseFloat(elem.textContent));
data = data.concat(values);
}
}
}
return data;
}
async extractExcelData(excelEmbedInfo, zip) {
console.log(excelEmbedInfo)
const excelFilePath = excelEmbedInfo.name
if (excelFilePath) {
const excelData = await zip.files[excelFilePath].async("nodebuffer");
console.log(excelData);
return this.parseExcelData(excelData);
} else {
console.error(`Excel file not found at path: ${excelFilePath}`);
return [];
}
}
parseExcelData(excelBuffer) {
// currently using 'xlsx' library to parse Excel buffer, would prob need to add this dep..
let workbook = XLSX.read(excelBuffer, {type: 'buffer'});
let sheetName = workbook.SheetNames[0];
let worksheet = workbook.Sheets[sheetName];
let data = XLSX.utils.sheet_to_json(worksheet, {header:1});
return data; // Flatten if the data structure is nested
} that returns [ '', 'Series 1', 'Series 2', 'Series 3' ],
[ 'Kategorie 1', 20, 20, 20 ],
[ 'Kategorie 2', 10, 10, 10 ],
[ 'Kategorie 3', 10, 10, 10 ],
[ 'Kategorie 4', 10, 10, 10 ]
]``` |
The <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart" Target="/ppt/charts/chart1.xml"/> Please see my latest commit. |
Hey @MP70, I've added an example to read data from a chart worksheets. I'm using a normal modifier to walk through rows and columns. I think it would be useful to have more "readers" in the future. |
Something to add to this discussion is the existing modifier will clean the underlying excel file but will not clean formulas, so if you modify a chart it will look fine, but then if you click "edit excel data" formulas will trigger, and if in the original file cells where references to elsewhere then the chart will break. This approach gives room to control things like that? |
setChartData throws
Error: Could not find file ppt/charts/undefinedundefined.xml@Recreated_Presentation_OUTO1.pptx at ArchiveJszip.<anonymous> (/Users/matt/dev/pptxtopptxgenjs/node_modules/pptx-automizer/dist/helper/archive/archive-jszip.js:57:23)
on these charts.
The text was updated successfully, but these errors were encountered: