troubleshooting Question

VB.NET Can't Find SpreadSheetDocument.Creat

Avatar of Michael Clymer
Michael Clymer asked on
ProgrammingVisual Basic.NETMicrosoft Visual Studio
3 Comments1 Solution314 ViewsLast Modified:

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

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

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

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

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

      ' Stylesheet
      workbookStylesPart = spreadSheet.WorkbookPart.AddNewPart(Of WorkbookStylesPart)()
      workbookStylesPart.Stylesheet = New Stylesheet()
    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!
Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros