生成Excel文档中设置最大行高 [英] Set maximum row height in generated excel document
问题描述
在我的web应用程序的用户可以得到Excel报表。现在的问题是:当行的一个细胞中含有长文本,因此所有的行是成长,Excel报表很糟糕。我需要设置最大行高度为我的Excel文档中的所有行。
In my web application users can get excel report. The problem is : when one of the cells in row contains long text, so all row is grow, and excel report looks bad. I need to set maximum row height for all rows in my excel document.
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选项没有找到这个功能。任何人可以帮助?
Can't find in excel options this function. Can anybody help?
推荐答案
您可以指定列的范围,然后可以调节宽度,它们的高度如下:
You can specify the range of columns and then can adjust width,height of them as below :
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
visit :http://msdn.microsoft.com/en-us/library/microsoft.office.tools.excel.namedrange.rowheight.aspx
这篇关于生成Excel文档中设置最大行高的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!