Solved

Problem to DocumentFormat

Posted on 2016-07-26
8
65 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 62

Expert Comment

by:Fernando Soto
Comment Utility
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
Comment Utility
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 62

Accepted Solution

by:
Fernando Soto earned 500 total points
Comment Utility
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
 
LVL 10

Author Comment

by:HuaMinChen
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 62

Expert Comment

by:Fernando Soto
Comment Utility
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 62

Expert Comment

by:Fernando Soto
Comment Utility
0
 
LVL 10

Author Comment

by:HuaMinChen
Comment Utility
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 62

Expert Comment

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

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

763 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now