Hi all,
I need help with changing values inside Excel part implemented in power point presentation.
I would like to know how to retrieve the relation to the Excel part, and how to explorer it.From my experience , I worked with PPTX files, so when I opened the file using: Package.Open(fileName, FileMode.Open, FileAccess.ReadWrite)I suppliy the file path, but if the excel is implemented inside the presentation file, how do I open it?
I'll be glad if you can supply some code examples.
Thanks
Eitan
I will retranslate myself.I have a PPTX file with XLSX sheet embedded inside it.I'am trying to change values inside the excel sheet.Is anyone can post some code example for it?Another problem I think will be, the image in the Media folder, that will not change even so the values in the excel were changed.
Appreciate your helpEitan.
Is any one knows how can I change Excel cells inside a PPTX file?If you can, please attached some code examples...
using this code, you can access the specific cell in the embedded spreadsheet in your PPT.
string fileName = "test.pptx"; using (PresentationDocument document = PresentationDocument.Open(fileName, true)) { SlideId slideId = (SlideId)document.PresentationPart.Presentation.SlideIdList.ChildElements[0]; SlidePart slidePart = (SlidePart)document.PresentationPart.GetPartById(slideId.RelationshipId.ToString()); Slide slide = slidePart.Slide; IEnumerable<DocumentFormat.OpenXml.Presentation.OleObject> oles = slide.Descendants<DocumentFormat.OpenXml.Presentation.OleObject>().Where(oleObj => oleObj.Name == "Worksheet"); foreach (DocumentFormat.OpenXml.Presentation.OleObject ole in oles.ToArray()) { EmbeddedPackagePart worksheetPart = (EmbeddedPackagePart)slidePart.GetPartById(ole.Id.ToString()); using (SpreadsheetDocument embedDocument = SpreadsheetDocument.Open(worksheetPart.GetStream(), true)) { WorksheetPart sheetPart = (WorksheetPart)embedDocument.WorkbookPart.GetPartById(embedDocument.WorkbookPart.Workbook.Descendants<Sheet>().Where(s => s.Name == "Sheet1").First().Id.ToString()); Worksheet sheet = sheetPart.Worksheet; Cell cell = sheet.Descendants<Cell>().Where(c => c.CellReference == "A1").First(); // modification } } }
Hi goodol,
I didnt try this code yet, but I would like you to answer me:if this way change the display image that describes the excel table?
sorry, but i'm not very clear about the meaning of "the display image that describes the excel table". you mean the image in the cell/cells?
Hi googol.
Nice peace of code...
Can you tell me who to refresh de worksheet to reflect the changes i made.
Thanks.