Click here to Skip to main content
16,018,802 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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[
Posted
Comments
Sergey Alexandrovich Kryukov 24-Sep-13 9:15am    
Let's see. After I have read your "uripart" (what is that?) and "How to concatenate the number of sheets" in the very beginning, I have no patience to read further.

The notion of "concatenation" is only applied to strings, but not to numbers. This phrase itself shows that you don't understand what you are talking about, and, even this is only a false impression (and in fact you clearly understand the subject). So, why would I read any further, if it can be a waste of time?

This is just to explain why it's important to phrase your question more or less accurately. (And of course it has nothing to do with English.)

What you can do? Click Improve question and...

—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900