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 16, 2020 9:03 am

hi,

i found textbox's autosize property did not work properly last year, but i have to use spire.xls in my company. in my project, i must know the text's width and height in pixel, so i can set the width and height of textbox according to the text's size. the problem is:

(1) how can i measure the text's size in pixel;

(2) how can i set the margin or padding for textbox;

thanks!

flame1149
 
Posts: 6
Joined: Thu Mar 07, 2019 1:31 pm

Thu Apr 16, 2020 11:04 am

Hello,

Thanks for your inquiry. Below is my reply to your questions.
1) Please refer to the following code.
Code: Select all
    //Get the text font
    IFont font = textbox.RichText.GetFont(0);
    Font f = new Font(font.FontName, (float)font.Size);
    //using System.Windows.Forms;
    Form form = new Form();
    Graphics g = form.CreateGraphics();
    //Measure the size of text
    SizeF s = g.MeasureString(textbox.Text, f);

2) Please refer to the following article to set margin for textbox. As for padding, our Spire.XLS is based on Microsoft Excel and there is no such setting in Microsoft Excel. Hope you can understand.
Set the internal margin of excel textbox in C#

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Sat Apr 18, 2020 12:58 am

rachel.lei wrote:Hello,

Thanks for your inquiry. Below is my reply to your questions.
1) Please refer to the following code.
Code: Select all
    //Get the text font
    IFont font = textbox.RichText.GetFont(0);
    Font f = new Font(font.FontName, (float)font.Size);
    //using System.Windows.Forms;
    Form form = new Form();
    Graphics g = form.CreateGraphics();
    //Measure the size of text
    SizeF s = g.MeasureString(textbox.Text, f);

2) Please refer to the following article to set margin for textbox. As for padding, our Spire.XLS is based on Microsoft Excel and there is no such setting in Microsoft Excel. Hope you can understand.
Set the internal margin of excel textbox in C#

Sincerely,
Rachel
E-iceblue support team


i understand, thank you very much!

flame1149
 
Posts: 6
Joined: Thu Mar 07, 2019 1:31 pm

Mon Apr 20, 2020 1:03 am

Hello,

Thanks for your feedback.
If you need further assistance, just feel free to contact us.
Have a nice day!

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Return to Spire.XLS