openxml sdk - Chart is not refreshing after updating Embedded excel part in open xml sdk 2.0 -


i trying update embedded excel part of chart in power point other excel file, updating embedded excel file chart.

one thing noticed is, once come "edit data" option can able see update in chart. please me how refresh chart in open xml

i using following code,

 presentationdocument mydestdeck = presentationdocument.open(@"presentation1.pptx", true);          presentationpart prespart = mydestdeck.presentationpart;         slidepart slidepart = prespart.slideparts.firstordefault();         chartpart chartpart1 = slidepart.chartparts.firstordefault();          embeddedpackagepart embeddedpackagepart1 = chartpart1.embeddedpackagepart;         embeddedpackagepart1.feeddata(new filestream(@"output12.xlsx", filemode.open, fileaccess.readwrite));          prespart.presentation.save();         mydestdeck.close(); 

please help

thanks in advance,

i have worked open xml in .docx context, suspect having same problem had when wanted update embedded chars in document.

assuming same approach took valid power point, chart has 2 datapoints in zip-package contains files. first have data-entry in excel files (which in word document located in /word/embeddings) besides have data-cache contains (for reason) cache of data showed in file in xml format. (located in /word/charts) new data effective @ once when file opened, need update thoose files well.

i solved first grabbing chart parts

using (wordprocessingdocument worddoc = wordprocessingdocument.open(name, true))             {                 var mainpart = worddoc.maindocumentpart; //indlæs hovedpart af dokumentet                 documentformat.openxml.packaging.chartpart[] charts = mainpart.chartparts.toarray(); //hent grafer             } 

you need dig documentformat.openxml.drawing @ chart want edit isolate documentformat.openxml.drawing.charts.chartreference there can charts id can in rels file path chart xml need edit.

i didn't write part of code in project, @ liberty share mess, here go. 1 ugly way of diggin bookmarkstart chartreference.

[note: relsrid dictionary id key , filename value.]

private string grab(bookmarkstart bookmarkstart)     {         //isolate chart         #region grab         var rids = relsrid;         documentformat.openxml.wordprocessing.drawing elem = null;         documentformat.openxml.drawing.charts.chartreference gd = null;         try         {             elem = bookmarkstart.nextsibling().elements<drawing>().elementat(0); //første forsøg på @ finde vores graf         }         catch (exception)         { //forsøg nummer 2             openxmlelement teste = bookmarkstart.nextsibling();             while (teste.localname.tolower() != "drawing")             {                 teste = teste.nextsibling();                 (int = 0; < teste.elements().count(); i++)                     if (teste.elementat(i).localname.tolower() == "drawing") teste = teste.elementat(i);             }             elem = (documentformat.openxml.wordprocessing.drawing)teste;         }         try         { //first try @ grabbing graph data             gd = (documentformat.openxml.drawing.charts.chartreference)elem.inline.graphic.graphicdata.elementat(0);         }         catch (exception)         { //second possible route             gd = (documentformat.openxml.drawing.charts.chartreference)elem.anchor.elements<graphic>().first().elements<graphicdata>().first().elementat(0);         }         var id = gd.id;         string matchname = "/word/" + rids[id.tostring()]; //create filepath         #endregion         return matchname;     } 

how handle getting filepath of chart xml you. don't approve of way, should give idea of how approach it.

when got path sorted out, can (using charts extracted in first code segment

public void editgraph(bookmarkstart bookmarkstart, documentformat.openxml.packaging.chartpart[] charts)     {         string check = grab(bookmarkstart);         chartpart chart = null;          (int = 0; < charts.count(); i++) //loop th         {             chart = charts[i];             if (check.tolower().equals(chart.uri.tostring().tolower()))                 break;         }         //chart contains chart-cache looking edit.     } 

you can choose how want edit data contains. choose pull out plot xml chart, remove chart, edit xml pulled out , put in. i'm can directly open-xml well. plot elements this

var plots = chart.chartspace.elements<documentformat.openxml.drawing.charts.chart>(); 

i wish knew more simple way explain it, proberbly best can do.

finally never did find way extract rels document, ended jumping zip-file , pull out.

i construct rels-dictionary used this

private dictionary<string, string> relsridtofile()     {     string rels;             using (memorystream memory = new memorystream())             {                 using (zipfile zip = zipfile.read("wordfile.docx"))                 {                     zipentry e = zip["word/_rels/document.xml.rels"];                     e.extract(memory);                 }                 using (streamreader reader = new streamreader(memory))                 {                     memory.seek(0, seekorigin.begin);                     rels = reader.readtoend();                 }             }         xmldatadocument xml = new xmldatadocument();         xml.loadxml(rels);         xmlnodelist xmlnode;         xmlnode = xml.getelementsbytagname("relationship");         dictionary<string, string> result = new dictionary<string, string>();         (int = 0; < xmlnode.count; i++)         {             var node = xmlnode[i];             var atts = node.attributes;             string id = "";             string target = "";             (int ii = 0; ii < atts.count; ii++)             {                 var att = atts[ii];                 if (att.name.tolower() == "id") id = att.value;                 if (att.name.tolower() == "target") target = att.value;             }             result[id] = target;         }         return result;     } 

good luck, , let me know if can clarify something.


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -