aspose.cell,Excel文件保存为pdf,文本框中文本与在Excel中显示效果不一致。CalculateTextSize计算的文本高度也没超过文本框,但是输出pdf时文本已溢出文本框
testPdf.zip (256.2 KB)
public static void testHeight()
{
//CellsHelper.DPI = 168;
Workbook workbook = new Workbook("D:\\input_testPdf.xlsm");
Worksheet sheet = workbook.Worksheets["sheet1"];
foreach (Shape shape in sheet.Shapes)
{
// 判断形状是否为文本框
if (shape is Aspose.Cells.Drawing.TextBox)
{
Aspose.Cells.Drawing.TextBox textBox = (Aspose.Cells.Drawing.TextBox)shape;
// 判断文本框的名称是否以"批注文本框"开头
if (textBox.Name.StartsWith("批注文本框"))
{
// 获取文本框的高度
double textBoxHeight = textBox.Height;
Console.WriteLine("textBoxHeight:" + textBoxHeight);
int[] estimatedTextHeight = textBox.CalculateTextSize();
Console.WriteLine("estimatedTextHeight:" + estimatedTextHeight[1]);
// 检查是否溢出
if (estimatedTextHeight[1] > textBoxHeight)
{
throw new OverflowException(
$"{sheet.Name}文本框内容溢出,请调整内容!"
);
}
}
}
}
workbook.Save("d:\\output_test.pdf");
}