We help IT Professionals succeed at work.

VB.NET Can't Find SpreadSheetDocument.Creat

290 Views
Last Modified: 2018-08-27
Hello,

I am using Visual Studio 2017, programming in VB.NET.
I have a reference in my project to DocumentFormat.OpenXml (SDK2.5, Version 2.5.5631.0, Runtime Version 4.0.30319)

At the start of the module, I have the following:
Imports DocumentFormat.OpenXml
Imports DocumentFormat.OpenXml.Packaging
Imports DocumentFormat.OpenXml.Spreadsheet

My code (plagiarized from Google) is as follows:
 Public Function CreateWorkbook(fileName As String) As SpreadsheetDocument
    Dim spreadSheet As SpreadsheetDocument = Nothing
    Dim sharedStringTablePart As SharedStringTablePart
    Dim workbookStylesPart As WorkbookStylesPart

    Try
      ' Create the Excel workbook
      spreadSheet = New SpreadsheetDocument.Create(fileName, SpreadsheetDocumentType.Workbook, False)

      ' Create the parts and the corresponding objects
      ' Workbook
      spreadSheet.AddWorkbookPart()
      spreadSheet.WorkbookPart.Workbook = New Workbook()
      spreadSheet.WorkbookPart.Workbook.Save()

      ' Shared string table
      sharedStringTablePart = spreadSheet.WorkbookPart.AddNewPart(Of SharedStringTablePart)()
      sharedStringTablePart.SharedStringTable = New SharedStringTable()
      sharedStringTablePart.SharedStringTable.Save()

      ' Sheets collection
      spreadSheet.WorkbookPart.Workbook.Sheets = New DocumentFormat.OpenXml.Spreadsheet.Sheets()
      spreadSheet.WorkbookPart.Workbook.Save()

      ' Stylesheet
      workbookStylesPart = spreadSheet.WorkbookPart.AddNewPart(Of WorkbookStylesPart)()
      workbookStylesPart.Stylesheet = New Stylesheet()
      workbookStylesPart.Stylesheet.Save()
    Catch exception As System.Exception
      'System.Windows.MessageBox.Show(exception.Message, "Excel OpenXML basics", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Hand)
    End Try

    Return spreadSheet
  End Function

My problem is with spreadSheet = New SpreadsheetDocument.Create(fileName, SpreadsheetDocumentType.Workbook, False). I have an error that "Type 'SpreadSheetDocument.Create' is not defined." How do I fix this error?

I am an old VBA programmer struggling in VB.NET,  thanks ahead of time, as any help would be much appreciated!
Comment
Watch Question

Senior Consultant
CERTIFIED EXPERT
Awarded 2017
Distinguished Expert 2019
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
Michael ClymerConsultant

Author

Commented:
Thanks that helped. It led me to see that I needed to add WindowsBase to my references.
Michael ClymerConsultant

Author

Commented:
Shaun was very speedy with a reply, and I do know that he would have helped me further, but with his suggestion, I discovered what the issue was. I needed to add WindowsBase to my references.

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions