• 怎么用Aspose.PDF 实现自动调整合并单元格的行?

    详细描述您的问题,有利于获得更好的解答
  • 回复

    建议参考如下代码: [C#]
     //Instantiate a new Workbook
    Workbook wb = new Workbook();
    //Get the first (default) worksheet
    Worksheet _worksheet = wb.Worksheets[0];
    //Create a range A1:B1
    Range range = _worksheet.Cells.CreateRange(0, 0, 1, 2);
    //Merge the cells
    range.Merge();
    //Insert value to the merged cell A1
    _worksheet.Cells[0, 0].Value = "A quick brown fox jumps over the lazy dog. A quick brown fox jumps over the lazy dog....end";
    //Create a style object
    Aspose.Cells.Style style = _worksheet.Cells[0, 0].GetStyle();
    //Set wrapping text on
    style.IsTextWrapped = true;
    //Apply the style to the cell
    _worksheet.Cells[0, 0].SetStyle(style);
    //Create an object for AutoFitterOptions
    AutoFitterOptions options = new AutoFitterOptions();
    //Set auto-fit for merged cells
    options.AutoFitMergedCells = true;
    //Autofit rows in the sheet(including the merged cells)
    _worksheet.AutoFitRows(options);
    //Save the Excel file
    wb.Save("e:\test2\autofitmergedcells.xlsx");
    [VB]
     'Instantiate a new Workbook
    Dim wb As New Workbook()
    'Get the first (default) worksheet
    Dim _worksheet As Worksheet = wb.Worksheets(0)
    'Create a range A1:B1
    Dim range As Range = _worksheet.Cells.CreateRange(0, 0, 1, 2)
    'Merge the cells
    range.Merge()
    'Insert value to the merged cell A1
    _worksheet.Cells(0, 0).Value = "A quick brown fox jumps over the lazy dog. A quick brown fox jumps over the lazy dog....end"
    'Create a style object
    Dim style As Aspose.Cells.Style = _worksheet.Cells(0, 0).GetStyle()
    'Set wrapping text on
    style.IsTextWrapped = True
    'Apply the style to the cell
    _worksheet.Cells(0, 0).SetStyle(style)
    'Create an object for AutoFitterOptions
    Dim options As New AutoFitterOptions()
    'Set auto-fit for merged cells
    options.AutoFitMergedCells = True
    'Autofit rows in the sheet(including the merged cells)
    _worksheet.AutoFitRows(options)
    'Save the Excel file
    wb.Save("e:test2autofitmergedcells.xlsx")
    
    如需其它帮助,欢迎来电咨询010-84827838,我们将竭诚为您服务!
文档管理文字处理技术
新闻资讯
单击获得帮助