c#导出 Excel 如何给单元格加边框
我百度了没找到适合我代码的写法我是调用的报表模板fmh.Guid=newGuid(Request.QueryString["infoguid"].ToString());...
我百度了没找到适合我代码的写法
我是调用的报表模板
fmh.Guid =new Guid(Request.QueryString["infoguid"].ToString());
fmh.PrintingDate = DateTime.Now;
FMH_Report_InfoLib.Update_print(fmh);
DataTable dt = (DataTable)ViewState["DataSource"];
Workbook wb = new Workbook();
Cells cell;
string path = Path.Combine(Server.MapPath("."), "Excel");
path = Path.Combine(path, "EmissionMonth.xls");
//string path = Server.MapPath(@"\Excel\DimensionQuery.xls");
wb.Open(path);
int sheet = 1;
int currsheet = 0;
int MaxRow = 60000;
int RowCount = 0;
int CurrRow = 9;
下面写出导出数据的部分代码
for (int i = 0; i < dt.Rows.Count; i++)
{
RowCount++;
if (RowCount > MaxRow)
{
RowCount = 0;
CurrRow = 1;
currsheet++;
}
cell = wb.Worksheets[currsheet].Cells;
cell[CurrRow, 1].PutValue(string.Format("{0:N2}",dt.Rows[i]["MachineCapacity"].ToString()));
cell[CurrRow, 2].PutValue(string.Format("{0:N2}",dt.Rows[i]["BoilerTonnTonnage"].ToString()));
cell[CurrRow, 3].PutValue(dt.Rows[i]["BoilerQuantity"].ToString());
} 展开
我是调用的报表模板
fmh.Guid =new Guid(Request.QueryString["infoguid"].ToString());
fmh.PrintingDate = DateTime.Now;
FMH_Report_InfoLib.Update_print(fmh);
DataTable dt = (DataTable)ViewState["DataSource"];
Workbook wb = new Workbook();
Cells cell;
string path = Path.Combine(Server.MapPath("."), "Excel");
path = Path.Combine(path, "EmissionMonth.xls");
//string path = Server.MapPath(@"\Excel\DimensionQuery.xls");
wb.Open(path);
int sheet = 1;
int currsheet = 0;
int MaxRow = 60000;
int RowCount = 0;
int CurrRow = 9;
下面写出导出数据的部分代码
for (int i = 0; i < dt.Rows.Count; i++)
{
RowCount++;
if (RowCount > MaxRow)
{
RowCount = 0;
CurrRow = 1;
currsheet++;
}
cell = wb.Worksheets[currsheet].Cells;
cell[CurrRow, 1].PutValue(string.Format("{0:N2}",dt.Rows[i]["MachineCapacity"].ToString()));
cell[CurrRow, 2].PutValue(string.Format("{0:N2}",dt.Rows[i]["BoilerTonnTonnage"].ToString()));
cell[CurrRow, 3].PutValue(dt.Rows[i]["BoilerQuantity"].ToString());
} 展开
2个回答
展开全部
给你一个我以前写的片段,看是否对你有帮助
//选取指定的单元格
var RowAll = sheet.get_Range(sheet.Cells[2, 2], sheet.Cells[20, 14]);
//指定对齐
RowAll.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter;
//指定文字大小
RowAll.Font.Size = 8;
//指定边框
RowAll.Borders.LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous;
//选取指定的单元格
var RowAll = sheet.get_Range(sheet.Cells[2, 2], sheet.Cells[20, 14]);
//指定对齐
RowAll.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter;
//指定文字大小
RowAll.Font.Size = 8;
//指定边框
RowAll.Borders.LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous;
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你用Spire.Xls.dll来设置Excel边框也是可以的,C#设置Excel边框
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询