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.

Thu Apr 18, 2024 1:09 pm

Hello,

I have been using Spire.XLS for C# for some time and have now gotten to a point where I need to show a textbox on a chartsheet. Inserting one on a normal worksheet works just fine and as expected but I can't seem to get the Textbox to show up on a chartsheet.

Spire.Xls.Workbook wb = new Spire.Xls.Workbook();
wb.Worksheets.Clear();
Spire.Xls.ChartSheet chart = wb.Charts.Add("Test");
chart.ChartType = Spire.Xls.ExcelChartType.ScatterLine;
var tb = chart.TextBoxes.AddTextBox(1,1,500,500);
tb.Text = "testesttesttesttesttesttesttesttesttesttesttesttestt";

Also, using a label with the same setup works and shows on the chartsheet, but none of the other shapes seem to show up. Any idea why this could be ?

alex_vicena
 
Posts: 2
Joined: Thu Apr 18, 2024 1:04 pm

Fri Apr 19, 2024 2:40 am

Hi,

Thanks for your inquiry.
The reason of your issue is the code is incorrect. I attach the complete code of creating chart and adding textbox for chart.

Code: Select all
 // Create a Workbook object
            Workbook workbook = new Workbook();

            workbook.Worksheets.Clear();

            // Add worksheet in the workbook
            Worksheet sheet = workbook.Worksheets.Add("test");

            // Insert data into the worksheet
            sheet.Range["A1"].Value = "Country";
            sheet.Range["A1"].Style.Font.IsBold = true;
            sheet.Range["A2"].Value = "Cuba";
            sheet.Range["A3"].Value = "Mexico";
            sheet.Range["A4"].Value = "France";
            sheet.Range["A5"].Value = "German";
            sheet.Range["B1"].Value = "Sales";
            sheet.Range["B1"].Style.Font.IsBold = true;
            sheet.Range["B2"].NumberValue = 6000;
            sheet.Range["B3"].NumberValue = 8000;
            sheet.Range["B4"].NumberValue = 9000;
            sheet.Range["B5"].NumberValue = 8500;

            // Add a new chart and set its type to Doughnut
            Chart chart = sheet.Charts.Add();
            chart.ChartType = ExcelChartType.ScatterLine;

            // Set the data range for the chart
            chart.DataRange = sheet.Range["A1:B5"];
            chart.SeriesDataFromRange = false;

            // Set the position of the chart on the worksheet
            chart.LeftColumn = 4;
            chart.TopRow = 2;
            chart.RightColumn = 12;
            chart.BottomRow = 22;

            // Set the chart title
            chart.ChartTitle = "Market share by country";
            chart.ChartTitleArea.IsBold = true;
            chart.ChartTitleArea.Size = 12;

         
            // Add a Textbox
            ITextBoxLinkShape textbox = chart.Shapes.AddTextBox();

            var tb = chart.TextBoxes.AddTextBox(1, 1, 500, 500);
            tb.Text = "testesttesttesttesttesttesttesttesttesttesttesttestt";


            // Save the modified workbook to a file named "CreateDoughnutChart.xlsx" in Excel 2013 format
            string output = @"../../output/CreateDoughnutChart.xlsx";
            workbook.SaveToFile(output, ExcelVersion.Version2013);

            // Dispose of the workbook object to release resources
            workbook.Dispose();


Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 1010
Joined: Tue Mar 08, 2022 2:02 am

Fri Apr 19, 2024 8:48 am

Hello,

Thank you for your answer though I fear it's not where the problem was, in your code you add a chart onto a worksheet and add the textboxes into it, that works perfectly fine, but the problem I found is when you try to add textboxes to "Chartsheets" not "Worksheets" to get a chartsheet you can insert a new sheet and select "Chart" instead of "Worksheet" like this

chartsheet insert.png
chartsheet insert.png (6.3 KiB) Viewed 6607 times


or by adding a Chart onto the workbook object and not the worksheet object like this

Code: Select all
Spire.Xls.Workbook wb = new Spire.Xls.Workbook();
Spire.Xls.ChartSheet chart = wb.Charts.Add("Chartsheet");


The chartsheet looks different like this example:

chartsheet.png
chartsheet.png (57.84 KiB) Viewed 6607 times


In this chartsheet there is text on the topleft and top right, this was done using labels because no other shapes seem to work. Please try to add a textbox onto a chartsheet.

Thank you very much for any help!

alex_vicena
 
Posts: 2
Joined: Thu Apr 18, 2024 1:04 pm

Fri Apr 19, 2024 9:39 am

Hi,

Thanks for your feedback.
I'm sorry I didn't catch the key point of your question at first. I tested again your scenario and reproduced your issue, I have logged it into our bug track system with the ticket number SPIREXLS-5216. Our Dev team will investigate and fix it. Once it is resolved, I’ll inform you in time.

Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 1010
Joined: Tue Mar 08, 2022 2:02 am

Thu May 23, 2024 10:03 am

Hi,

Thanks for your patiently waiting.
I’m glad to inform you that the latest version of Spire.Xls 14.5.3 include your fix with the ticket number browse/SPIREXLS-5216.
website: https://www.e-iceblue.com/Download/down ... t-now.html
Nugut: https://www.nuget.org/packages/Spire.XLS/14.5.3

Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 1010
Joined: Tue Mar 08, 2022 2:02 am

Return to Spire.XLS