Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Wed Apr 17, 2019 9:03 am

Hi. This is my first time using pivot in spire. I do as same syntax as in the guide program, but unfortunately, there is an error.
The error says "String cannot be empty."

Here is the code that I've write,

Code: Select all
Public Sub CreatePivot()
        Dim workbook As New Workbook()
        workbook.LoadFromFile("1.XLSX")
        Dim sheet As Worksheet = workbook.Worksheets(0)
        sheet.Name = "Pending Invoice"  'The error says that ---->Name of worksheet must be unique in a workbook. but that is the name of my worksheet.
        Dim sheet2 As Worksheet = workbook.CreateEmptySheet()
        sheet2.Name = "Pivot Table"
        Dim dataRange As CellRange = sheet.Range("A1:AJ25")
        Dim cache As PivotCache = workbook.PivotCaches.Add(dataRange) 'the error is ----------> "String cannot be empty."
        Dim pt As PivotTable = sheet2.PivotTables.Add("Pivot Table", sheet.Range("A1"), cache)
        Dim r1 = pt.PivotFields("Project")
        r1.Axis = AxisTypes.Row
        pt.Options.RowHeaderCaption = "Project"

        Dim r2 = pt.PivotFields("Aging Date")
        r2.Axis = AxisTypes.Row

        Dim r3 = pt.PivotFields("Del No")
        r3.Axis = AxisTypes.Row

        Dim r4 = pt.PivotFields("Ship Qty")
        r4.Axis = AxisTypes.Row

        Dim r5 = pt.PivotFields("Ext Cost")
        r5.Axis = AxisTypes.Row

        pt.DataFields.Add(pt.PivotFields("Aging Date"), "Aging Date", SubtotalTypes.Sum)
        pt.DataFields.Add(pt.PivotFields("Del No"), "Total of Pending Invoice", SubtotalTypes.Sum)
        pt.DataFields.Add(pt.PivotFields("Ship Qty"), "Pending Qty", SubtotalTypes.Sum)
        pt.DataFields.Add(pt.PivotFields("Ext Cost"), "Pending Amount (USD)", SubtotalTypes.Sum)

        pt.BuiltInStyle = PivotBuiltInStyles.PivotStyleMedium12
        workbook.SaveToFile("1.XLSX", ExcelVersion.Version2010)
        System.Diagnostics.Process.Start("1.XLSX")

sitizalekoh
 
Posts: 15
Joined: Thu Apr 04, 2019 2:29 am

Wed Apr 17, 2019 11:38 am

Hello,

Thanks for your inquiry.
According to your testing file which you provided in email, the data range should be from the second worksheet but not the first worksheet, and the name of second worksheet also is “Pending Invoice”. Thus, there is an error when you set the same name. Please refer to the following modified code. But unfortunately, I encountered an problem like the attachment shows when testing it with the latest Spire.XLS Pack(Hotfix) Version:9.4.6. This issue will be submitted to our Dev team for further investigating and fixing, if there is any update, I will let you know. Sorry for the inconvenience caused.
Code: Select all
Dim workbook As New Workbook()
workbook.LoadFromFile("1.XLSX")
Dim sheet As Worksheet = workbook.Worksheets(1)
'sheet.Name = "Pending Invoice"
Dim sheet2 As Worksheet = workbook.CreateEmptySheet()
sheet2.Name = "Pivot Table"
Dim dataRange As CellRange = sheet.Range("A1:AJ25")
Dim cache As PivotCache = workbook.PivotCaches.Add(dataRange) '
Dim pt As PivotTable = sheet2.PivotTables.Add("Pivot Table", sheet2.Range("A1"), cache)
Dim r1 = pt.PivotFields("Project")
r1.Axis = AxisTypes.Row
pt.Options.RowHeaderCaption = "Project"
Dim r2 = pt.PivotFields("Aging Date")
r2.Axis = AxisTypes.Row
Dim r3 = pt.PivotFields("Del No")
r3.Axis = AxisTypes.Row
Dim r4 = pt.PivotFields("Ship Qty")
r4.Axis = AxisTypes.Row
Dim r5 = pt.PivotFields("Ext Cost")
r5.Axis = AxisTypes.Row
pt.DataFields.Add(pt.PivotFields("Aging Date"), "Aging Date", SubtotalTypes.Sum)
pt.DataFields.Add(pt.PivotFields("Del No"), "Total of Pending Invoice", SubtotalTypes.Sum)
pt.DataFields.Add(pt.PivotFields("Ship Qty"), "Pending Qty", SubtotalTypes.Sum)
pt.DataFields.Add(pt.PivotFields("Ext Cost"), "Pending Amount (USD)", SubtotalTypes.Sum)
pt.BuiltInStyle = PivotBuiltInStyles.PivotStyleMedium12
workbook.SaveToFile("result.xlsx", ExcelVersion.Version2010)

Sincerely,
Lisa
E-iceblue support team
Attachments
problem.zip
(9.8 KiB) Downloaded 181 times
User avatar

Lisa.Li
 
Posts: 1261
Joined: Wed Apr 25, 2018 3:20 am

Mon Apr 22, 2019 12:13 am

Hi, is there any update due the Spire HotFix. Thanks. :)

sitizalekoh
 
Posts: 15
Joined: Thu Apr 04, 2019 2:29 am

Mon Apr 22, 2019 1:54 am

Hello,

Thank you for following up.
I am sorry to tell that there is no significant progress yet. Our Dev team would keep looking into it. Once there is any good news, I will let you know. Thanks in advance for your patience.

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1261
Joined: Wed Apr 25, 2018 3:20 am

Mon May 13, 2019 11:09 am

Hello,

Glad to inform you that the reported issue been fixed in Spire.XLS Pack(Hotfix) Version:9.5.4. Please download it from the following links.
Website:https://www.e-iceblue.com/Download/download-excel-for-net-now.html
Nuget:https://www.nuget.org/packages/Spire.XLS/

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1261
Joined: Wed Apr 25, 2018 3:20 am

Return to Spire.XLS