We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Excel的文本框大小自动适应文字大小

请问,有没有方法可以把excel中的文本框根据内容自动变大小?

@speedasia,

请参阅以下示例代码来完成您的任务并供您参考:
例如
样例代码:

//Instantiate a new workbook
            Workbook workbook = new Workbook();
            //Get the first worksheet
            Worksheet sheet = workbook.Worksheets[0];
            //Get the Shape Collection
            ShapeCollection shapes = sheet.Shapes;
            //Add the TextBox shape
            Shape textbox = shapes.AddShape(MsoDrawingType.TextBox, 1, 0, 1, 0, 50, 300);
            //Resize the Textbox automatically
            textbox.TextFrame.AutoSize = true;
            //Set the contents / text
            textbox.Text = "Test...Aspose.Cells for SharePoint is easy to install and lets you convert and combine documents from within SharePoint.It supports spreadsheet processing, CSV, text, portable and other file formats, including XLS, XLSX and PDF etc....Aspose Team";
            //Calculate text size
            int[] size = textbox.CalculateTextSize();
            //Set width and height of the Textbox
            textbox.Width = size[0];
            textbox.Height = size[1];
            //Save the Excel file
            workbook.Save("e:\\test2\\outTextBox_resized1.xlsx");

希望这个对你有帮助。