@@ -11,6 +11,7 @@ import { RootPresTemplate } from '../interfaces/root-pres-template';
1111export class Chart extends Shape implements IChart {
1212 sourceWorksheet : number | string ;
1313 targetWorksheet : number | string ;
14+ worksheetFilePrefix : string ;
1415
1516 constructor ( shape : ImportedElement ) {
1617 super ( shape ) ;
@@ -92,7 +93,7 @@ export class Chart extends Shape implements IChart {
9293 async readWorkbook ( ) : Promise < Workbook > {
9394 const worksheet = await FileHelper . extractFromArchive (
9495 this . targetArchive ,
95- `ppt/embeddings/Microsoft_Excel_Worksheet ${ this . targetWorksheet } .xlsx` ,
96+ `ppt/embeddings/${ this . worksheetFilePrefix } ${ this . targetWorksheet } .xlsx` ,
9697 'nodebuffer' ,
9798 ) ;
9899 const archive = await FileHelper . extractFileContent (
@@ -140,7 +141,7 @@ export class Chart extends Shape implements IChart {
140141 type : 'nodebuffer' ,
141142 } ) ;
142143 this . targetArchive . file (
143- `ppt/embeddings/Microsoft_Excel_Worksheet ${ this . targetWorksheet } .xlsx` ,
144+ `ppt/embeddings/${ this . worksheetFilePrefix } ${ this . targetWorksheet } .xlsx` ,
144145 worksheet ,
145146 ) ;
146147 }
@@ -149,10 +150,14 @@ export class Chart extends Shape implements IChart {
149150 await this . copyChartFiles ( ) ;
150151
151152 const wbRelsPath = `ppt/charts/_rels/chart${ this . sourceNumber } .xml.rels` ;
153+ const wbEmbeddingsPath = `../embeddings/` ;
154+
155+ this . worksheetFilePrefix = await this . getWorksheetFilePrefix ( wbRelsPath ) ;
156+
152157 const worksheets = await XmlHelper . getTargetsFromRelationships (
153158 this . sourceArchive ,
154159 wbRelsPath ,
155- '../embeddings/Microsoft_Excel_Worksheet' ,
160+ ` ${ wbEmbeddingsPath } ${ this . worksheetFilePrefix } ` ,
156161 '.xlsx' ,
157162 ) ;
158163 const worksheet = worksheets [ 0 ] ;
@@ -164,6 +169,25 @@ export class Chart extends Shape implements IChart {
164169 await this . editTargetWorksheetRel ( ) ;
165170 }
166171
172+ async getWorksheetFilePrefix (
173+ targetRelFile : string ,
174+ ) {
175+ const relationTargets = await XmlHelper . getTargetsFromRelationships (
176+ this . sourceArchive ,
177+ targetRelFile ,
178+ `../embeddings/` ,
179+ '.xlsx' ,
180+ ) ;
181+
182+ let wbPath = relationTargets [ 0 ] . file
183+ . replace ( `../embeddings/` , '' )
184+ . replace ( '.xlsx' , '' )
185+
186+ const wbTitle = wbPath . match ( / ^ ( .+ ?) ( \d + ) * $ / )
187+
188+ return wbTitle [ 0 ]
189+ }
190+
167191 async appendTypes ( ) : Promise < void > {
168192 await this . appendChartExtensionToContentType ( ) ;
169193 await this . appendChartToContentType ( ) ;
@@ -239,7 +263,7 @@ export class Chart extends Shape implements IChart {
239263 case 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/package' :
240264 element . setAttribute (
241265 'Target' ,
242- `../embeddings/Microsoft_Excel_Worksheet ${ this . targetWorksheet } .xlsx` ,
266+ `../embeddings/${ this . worksheetFilePrefix } ${ this . targetWorksheet } .xlsx` ,
243267 ) ;
244268 break ;
245269 case 'http://schemas.microsoft.com/office/2011/relationships/chartColorStyle' :
@@ -257,9 +281,9 @@ export class Chart extends Shape implements IChart {
257281 async copyWorksheetFile ( ) : Promise < void > {
258282 await FileHelper . zipCopy (
259283 this . sourceArchive ,
260- `ppt/embeddings/Microsoft_Excel_Worksheet ${ this . sourceWorksheet } .xlsx` ,
284+ `ppt/embeddings/${ this . worksheetFilePrefix } ${ this . sourceWorksheet } .xlsx` ,
261285 this . targetArchive ,
262- `ppt/embeddings/Microsoft_Excel_Worksheet ${ this . targetWorksheet } .xlsx` ,
286+ `ppt/embeddings/${ this . worksheetFilePrefix } ${ this . targetWorksheet } .xlsx` ,
263287 ) ;
264288 }
265289
0 commit comments