Join
Sign in
Search Options
Search Everything
Search Formats
Home
Blog
Resources
Forums
About Open XML
More ...
Home
»
Forums
»
Formats
»
SpreadsheetML
»
Read WorkShhet From Workbook
Read WorkShhet From Workbook
Formats
Discussions about working with different Open XML Formats
Get this RSS feed
Details
1
Reply
1
Subscriber
Posted
over 2 years ago
Options
Subscribe via RSS
Share this
SpreadsheetML
Read WorkShhet From Workbook
rated by 0 users
This post has
1 Reply |
1
Follower
mesteves
40
Posted by
mesteves
on
Wed, Mar 10 2010 1:27 PM
rated by 0 users
Post Points: 20
Read WorkShhet From Workbook
Hi, I'm exploring the open XML format and i'm having some trouble to achieve something that i think must be really easy. Here's the case:
1 - Have one excel document, where the user fills in some fields (only the first sheet is manipulated - is it possible to get SheetByName?)
2 - A converter (exe), reads the excel file, and extracts the xml with all the data that the user filled in (the first worksheet) and saves it.
3 - The converter after saving the xml, applyies a transformation (xsl) and originates a new message (xml format) for integration (calling webservice for ex).
// Access the main Workbook part, which contains all references.
WorkbookPart wbPart = xlPack.WorkbookPart;
// Get the first worksheet.
WorksheetPart wsPart = wbPart.WorksheetParts.First();
XmlDocument doc = new XmlDocument();
//This Actually gets the sheet information,however fails if document has more or less sheet - want to get sheet by name
//Seen some examples that navigate thg
Stream data = xlPack.Parts.ElementAt(2).OpenXmlPart.Parts.ElementAt(4).OpenXmlPart.GetStream();
doc.Load(data);
doc.Save("sheet.xml");
Best regards and thank you for your help.
Manuel
Best regards, Manuel
Intergen
2610
Posted by
Intergen
on
Tue, Mar 16 2010 2:59 PM
rated by 0 users
Post Points: 5
Re: Read WorkShhet From Workbook
Hi Manuel
This code should make it work by retrieving the WorksheetPart by sheet name (works with one or many sheets):
Sheet sheet = wbPart.Workbook.Descendants().Where(s => s.Name == "MainSheet").FirstOrDefault();
WorksheetPart wsPart = (WorksheetPart)wbPart.GetPartById(sheet.Id);
XmlDocument doc = new XmlDocument();
Stream data = wsPart.GetStream();
doc.Load(data);
doc.Save("sheet.xml");
Page 1 of 1 (2 items)