[英]Set maximum row height in generated excel document
在我的Web應用程序中,用戶可以獲得excel報告。 問題是:當行中的一個單元格包含長文本時,所有行都會增長,而excel報表看起來很糟糕。 我需要為excel文檔中的所有行設置最大行高。
public bool UseOldFormat { get; set; }
public ExcelFile GetExcelFile()
{
var excel = new ExcelFile();
if (!string.IsNullOrEmpty(SourceFileName))
{
if (SourceFileName.EndsWith("xls"))
{
excel.LoadXls(SourceFileName);
}
else
{
excel.LoadXlsx(SourceFileName, XlsxOptions.PreserveMakeCopy);
}
}
return excel;
}
public void GenerateReport(string fileName)
{
ExcelFile excel = GetExcelFile();
InsertDataInExcel(excel);
if (UseOldFormat)
{
excel.SaveXls(fileName);
}
else
{
excel.SaveXlsx(fileName);
}
}
在excel選項中找不到此功能。 有人可以幫忙嗎?
您可以指定列的范圍,然后可以調整它們的寬度,高度,如下所示:
Microsoft.Office.Tools.Excel.NamedRange setColumnRowRange;
private void SetColumnAndRowSizes()
{
setColumnRowRange = this.Controls.AddNamedRange(
this.Range["C3", "E6"], "setColumnRowRange");
this.setColumnRowRange.ColumnWidth = 20;
this.setColumnRowRange.RowHeight = 25;
setColumnRowRange.Select();
}
訪問:http://msdn.microsoft.com/en-us/library/microsoft.office.tools.excel.namedrange.rowheight.aspx
如果你只有一個行太高的文件,這個宏可以解決問題:
(由您決定,Oleg,如何將其集成到文檔創建工具中,以防萬一)
Sub MaxRowHeight()
Dim Re As Long
Re = ActiveCell.SpecialCells(xlLastCell).Row
For i = 1 To Re
If Rows(i).Height > 43.2 Then Rows(i).RowHeight = 43.2
Next i
End Sub
積分轉到這篇文章和那里的討論:
http://excelribbon.tips.net/T010381_Adjusting_to_a_Maximum_Row_Height.html
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.