更改单元格的宽度与更改列的宽度相同
看看这有帮助吗?(未经测试)
// Set the column width
public void SetColWdth(string rng, double wdth)
{
Range = excelSheet.GetType().InvokeMember("Range",
BindingFlags.GetProperty,null, excelSheet, new object [] {rng});
object [] args = new object [] {wdth};
Range. GetType().InvokeMember ("Columnwdth",
BindingFlags.SetProperty, null, Range, args);
}
对于字体,看看这是否有帮助?
从上面的链接中引用以防万一它死了
foreach (string line in header)
{
Object entireRow = GetRow(sheet, columnCount, rowOffset);
entireRow.GetType().InvokeMember("MergeCells",
BindingFlags.SetProperty, null, entireRow,
new object[] { true });
entireRow.GetType().InvokeMember("HorizontalAlignment",
BindingFlags.SetProperty, null, entireRow, new object[] { 3 });
Object tlCell = GetCell(sheet, 1, rowOffset);
tlCell.GetType().InvokeMember("Value2", BindingFlags.SetProperty,
null, tlCell, new object[] { "'" + line });
Object font = tlCell.GetType().InvokeMember("Font",
BindingFlags.GetProperty, null, tlCell, null);
rowOffset++;
}
for (int col = 0; col < data.Columns.Count; col++)
{
Object test = GetCell(sheet, col + 1, rowOffset);
//DataTable Headers
{
Object erow = test.GetType().InvokeMember("EntireRow",
BindingFlags.GetProperty, null, test, null);
Object font = erow.GetType().InvokeMember("Font",
BindingFlags.GetProperty, null, erow, null);
erow.GetType().InvokeMember("HorizontalAlignment",
BindingFlags.SetProperty, null, erow, new object[] { 3 });
font.GetType().InvokeMember("Bold", BindingFlags.SetProperty,
null, font, new object[] { true });
test.GetType().InvokeMember("Value2", BindingFlags.SetProperty,
null, test, new object[] { data.Columns[col].ColumnName.ToString() });
}
}