Solved

Problem to DocumentFormat

Posted on 2016-07-26
8
109 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
  • 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 10

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
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 
LVL 10

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 10

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
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…

765 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