Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi Guys,

I have a program that creates xml files, I have to import these into XLSX spread sheets. I can do this using COM but when the xml file gets big (+50mb) it can up to an hour to open. I've done some looking around and I have found OpenXML - which is apparently faster.

I've had a play around and found what looks like it should work:

XML
string fileName = @"xxx.xlsx";
SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Create(fileName, SpreadsheetDocumentType.Workbook);
WorkbookPart workbookpart = spreadsheetDocument.AddWorkbookPart();
workbookpart.Workbook = new Workbook();
WorksheetPart worksheetPart = workbookpart.AddNewPart<WorksheetPart>();
worksheetPart.Worksheet = new Worksheet(new SheetData());
Sheets sheets = spreadsheetDocument.WorkbookPart.Workbook.AppendChild<Sheets>(new Sheets());
Sheet sheet = new Sheet() { Id = spreadsheetDocument.WorkbookPart.GetIdOfPart(worksheetPart), SheetId = 1, Name = "mySheet1" };
XmlDocument xwb = new XmlDocument();
xwb.Load(@"Data.xml");
Stream wbStream = worksheetPart.GetStream();
xwb.Save(wbStream);
sheets.Append(sheet);
workbookpart.Workbook.Save();
spreadsheetDocument.Close();



has anyone had experience of using OpenXML?
any guidance would be great! :)

many thanks,

Phil
Posted
Comments
Sergey Alexandrovich Kryukov 7-Jul-13 23:14pm    
You did not mention any problem. If your question is "has anyone had experience...", this cannot be a valid answerable question. Yes, many had, so how would it help you?
—SA
lanep 8-Jul-13 0:20am    
Hi Sergey,
Sorry, i'll clarify. From the little I have found out using xml files with OpenXML the above code should work, but doesn't. The xlsx file gets created and has a sheet called "mySheet1" but it is empty.
so my question is, do you know how to copy the contents of an xml file into a xlsx file.

many thanks,
Phil

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