Solved

Problem to DocumentFormat

Posted on 2016-07-26
8
93 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

777 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