I am trying to open .xlsx file for save and update.I have made xml as according to template.But when I have number of sheets .How to concatenate the number of sheets.All sheets are not necessary
public void copyCustomXml(string path)
{
try
{
ZipFile zip = new ZipFile(path);
Stream documentXml = readDocumentxml(zip);
XmlDocument xmlDoc_document = new XmlDocument();
xmlDoc_document.Load(documentXml);
zip.Close();
string customXmlpath;
XmlDocument xmlDoc = new XmlDocument();
//save document.xml,beefAuditSummary.xml as custom xml
using (Package package = Package.Open(path, FileMode.Open, FileAccess.ReadWrite))
{
System.Uri uriPartTarget = new System.Uri("/docProps/mcdonald.xml", System.UriKind.Relative);
customXmlpath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
customXmlpath = customXmlpath + @"\mcdonald.xml";
xmlDoc.Load(customXmlpath);
PackagePart customXml = package.CreatePart(uriPartTarget, "application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml");
//copy xml inside .xslx file
using (Stream partStream = customXml.GetStream(FileMode.Create, FileAccess.ReadWrite))
{
xmlDoc.Save(partStream);
}
System.Uri uriPartTargetdocxml = new System.Uri("/worksheets/sheet2.xml $ /worksheets/sheet3.xml $ /worksheets/sheet4.xml && /worksheets/sheet5.xml $ /worksheets/sheet6.xml $ /worksheets/sheet7.xml $ /worksheetssheet8.xml", System.UriKind.Relative);
if (!package.PartExists(uriPartTargetdocxml))
{
PackagePart customXmldoc = package.CreatePart(uriPartTargetdocxml, "application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml");
//copy document.xml inside .xslx file
using (Stream partStream = customXmldoc.GetStream(FileMode.Create, FileAccess.ReadWrite))
{
xmlDoc_document.Save(partStream);
}
}
else
{
package.DeletePart(uriPartTargetdocxml);
PackagePart customXmldoc = package.CreatePart(uriPartTargetdocxml, "application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml");
//copy document.xml inside .xslx file
using (Stream partStream = customXmldoc.GetStream(FileMode.Create, FileAccess.ReadWrite))
{
xmlDoc_document.Save(partStream);
}
}
}
//return frtDetails;
}
catch (Exception ex)
{
throw ex;
}
But it will give error at uripart part saying the rule are not as per opoenxml at the line
System.Uri uriPartTargetdocxml = new System.Uri("/worksheets/sheet2.xml $ /worksheets/sheet3.xml $ /worksheets/sheet4.xml && /worksheets/sheet5.xml $ /worksheets/sheet6.xml $ /worksheets/sheet7.xml $ /worksheetssheet8.xml", System.UriKind.Relative);
if (!package.PartExists(uriPartTargetdocxml))
i have to make these sheets concate to get the actual path anyone please help[