How to get a string and create a object in an excel file using Insert - Text

Hi Experts

I read the graph data from one file and write to a new book, in the original workbook the graph is on a separate sheet and on this graph there are labels made through insert -> text, how can I get the text that is recorded in them.

And also it may be that these inserts are not enough and you need to create a new one, also the question is how to create such an insert with your text.

It is necessary to read only black inscriptions, blue ones are always on the chart

I attach how it looks in the file.


Attachment: excelfiles_6ad1cbea.zip

1 Reply 1 reply marked as answer

RS Ramya Sivakumar Syncfusion Team February 9, 2022 11:52 AM UTC

Hi Dmitriy, 

Greetings from Syncfusion. 

Please use the following code snippet to read a text of a textbox present in a chart and also to create a text box in the worksheet. 

Code snippet: 
using (ExcelEngine excelEngine = new ExcelEngine()) 
    IApplication application = excelEngine.Excel; 
    application.DefaultVersion = ExcelVersion.Xlsx; 

    IWorkbook workbook = application.Workbooks.Open("Sample.xlsx", ExcelOpenType.Automatic); 
    IWorksheet worksheet = workbook.Worksheets[0]; 

    //Read the text 
    for (int i = 0; i < worksheet.Charts.Count; i++) 
    { 
         for (int j = 0; j < worksheet.Charts[i].TextBoxes.Count; j++) 
         { 
              String text = worksheet.Charts[i].TextBoxes[j].Text; 
         } 
    } 

    //Creates a new text box in the chart 
    ITextBoxShape textbox = worksheet.Charts[0].TextBoxes.AddTextBox(2, 2, 80, 300); 
    textbox.Text = "Text Box in the chart"; 

    workbook.SaveAs("Output.xlsx"); 


Regards, 
Ramya. 


Marked as answer
Loader.
Up arrow icon