Solved

Problem to DocumentFormat

Posted on 2016-07-26
8
192 Views
Last Modified: 2016-07-27
Hi,
How to correct this
Error	2	'DocumentFormat.OpenXml.Packaging.SpreadsheetDocument' does not contain a definition for 'WorksheetParts' and no extension method 'WorksheetParts' accepting a first argument of type 'DocumentFormat.OpenXml.Packaging.SpreadsheetDocument' could be found (are you missing a using directive or an assembly reference?)

Open in new window


due to 2nd line below?

                    SpreadsheetDocument Book0 = SpreadsheetDocument.Open(openFileDialog1.FileName, false);
                    WorksheetPart worksheetPart = Book0.WorksheetParts.First();

Open in new window

0
Comment
Question by:HuaMinChen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 41729400
I suspect you have the following DLL, DocumentFormat.OpenXml.dll, added to your references in your application but do you have the following using statements
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Spreadsheet;

Open in new window

0
 
LVL 11

Author Comment

by:HuaMinChen
ID: 41730527
How to correct
Error	2	'DocumentFormat.OpenXml.Packaging.SpreadsheetDocument' does not contain a definition for 'Worksheets' and no extension method 'Worksheets' accepting a first argument of type 'DocumentFormat.OpenXml.Packaging.SpreadsheetDocument' could be found (are you missing a using directive or an assembly reference?)

Open in new window

due to last line below?
                    using (SpreadsheetDocument Book0 = SpreadsheetDocument.Open(openFileDialog1.FileName, true))
                    {

                        Worksheet0 = (Excel.Worksheet)Book0.Worksheets.Add();

Open in new window

0
 
LVL 63

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 41730534
Did you place these two lines of code at the top of the code file your working in?
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Spreadsheet;

Open in new window

0
The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

 
LVL 11

Author Comment

by:HuaMinChen
ID: 41730647
Yes, I did.

How to add one new Worksheet to WorkbookPart below?
                        foreach (Excel.Worksheet sheet in Book0.WorkbookPart.Workbook.Descendants<Sheet>().Where(s => s.Name == Worksheet0))
                        {
                            ...

Open in new window

0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 41731103
Seeming you are no longer having the original problem you have posted in this question. Please close this thread by assigning the points to the solution that solved the issue and opening a new question for your last post. Thanks.
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 41731125
0
 
LVL 11

Author Comment

by:HuaMinChen
ID: 41732239
Thanks a lot.
How to resolve
Error	3	Cannot implicitly convert type 'Microsoft.Office.Interop.Excel.Sheets' to 'DocumentFormat.OpenXml.Spreadsheet.Worksheet'. An explicit conversion exists (are you missing a cast?)	C:\App\WindowsFormsApplication5\WindowsFormsApplication2\Form1.cs	237	71	WindowsFormsApplication2
Error	4	The type 'Microsoft.Office.Interop.Excel.Sheets' cannot be used as type parameter 'T' in the generic type or method 'DocumentFormat.OpenXml.OpenXmlElement.GetFirstChild<T>()'. There is no implicit reference conversion from 'Microsoft.Office.Interop.Excel.Sheets' to 'DocumentFormat.OpenXml.OpenXmlElement'.	C:\App\WindowsFormsApplication5\WindowsFormsApplication2\Form1.cs	237	71	WindowsFormsApplication2
Error	5	'Sheets' is an ambiguous reference between 'Microsoft.Office.Interop.Excel.Sheets' and 'DocumentFormat.OpenXml.Spreadsheet.Sheets'	C:\App\WindowsFormsApplication5\WindowsFormsApplication2\Form1.cs	237	119	WindowsFormsApplication2

Open in new window


due to this line?
                DocumentFormat.OpenXml.Spreadsheet.Worksheet sheets = spreadSheet.WorkbookPart.Workbook.GetFirstChild<Sheets>();

Open in new window

0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 41732249
Sorry but I have not worked with Excel through code.
0

Featured Post

Tutorials alone can't teach real engineering

So we built better training tools.

-Hands-on Labs
-Instructor Mentoring
-Scenario-Based Tests
-Dedicated Cloud Servers

All at your fingertips. What are you waiting for?

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question