Worksheet ws = wb.Worksheets[0]
Cells cell = ws.Cells
//定义并获取导出的数据源
string[,] _ReportDt = new string[table.Rows.Count, table.Columns.Count]
for (int i = 0i <槐伍 table.Rows.Counti++)
{
for (int j = 0j <table.Columns.Countj++)
{
_ReportDt[i, j] = Convert.ToString(table.Rows[i][j])
}
}
int columnstart = 0
//设置行高
for (int k = 0k <= columnstartk++) { cell.SetRowHeight(k, 24)}
//设置字体样式铅漏或
Style style0 = wb.Styles[wb.Styles.Add()]
style0.HorizontalAlignment = TextAlignmentType.Center//文字居中
style0.Font.Name = "宋体"
style0.Font.IsBold = true//设置粗体
style0.Font.Size = 10//设置字体大小搜御
Style style1 = wb.Styles[wb.Styles.Add()]
style1.HorizontalAlignment = TextAlignmentType.Center//文字居中
style1.Font.Name = "宋体"
style1.Font.Size = 10//设置字体大小
style1.BackgroundColor = System.Drawing.Color.BlueViolet
style1.ForegroundColor = System.Drawing.Color.White
style1.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin
style1.Borders[BorderType.TopBorder].Color = Color.Black
style1.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin
style1.Borders[BorderType.BottomBorder].Color = Color.Black
style1.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thin
style1.Borders[BorderType.LeftBorder].Color = Color.Black
style1.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thin
style1.Borders[BorderType.RightBorder].Color = Color.Black
Style style2 = wb.Styles[wb.Styles.Add()]
style2.HorizontalAlignment = TextAlignmentType.Left
style2.Font.Size = 9
style2.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin
style2.Borders[BorderType.TopBorder].Color = Color.Black
style2.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin
style2.Borders[BorderType.BottomBorder].Color = Color.Black
style2.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thin
style2.Borders[BorderType.LeftBorder].Color = Color.Black
style2.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thin
style2.Borders[BorderType.RightBorder].Color = Color.Black
//给单元格关联样式
for (int k = 0k <= columnstartk++)
{
if (k == 0)
{
cell["A" + (k + 1).ToString()].SetStyle(style0)
}
else
{
cell["A" + (k + 1).ToString()].SetStyle(style1)
}
}
//设置Execl列名
for (int i = 0i <table.Columns.Counti++)
{
cell[columnstart, i].PutValue(Convert.ToString(table.Columns[i].ColumnName))
cell[columnstart, i].SetStyle(style1)
}
//设置单元格内容
int posStart = columnstart + 1
for (int i = 0i <table.Rows.Counti++)
{
for (int j = 0j <table.Columns.Countj++)
{
if (j == 9)
{
int sy = _ReportDt[i, j] == "0" ? 0 : Convert.ToInt32(_ReportDt[i, j])
cell[i + posStart, j].PutValue(sy)
cell[i + posStart, j].SetStyle(style2)
}
else
{
string sy = _ReportDt[i, j] == "0" ? "" : Convert.ToString(_ReportDt[i, j])
cell[i + posStart, j].PutValue(sy)
cell[i + posStart, j].SetStyle(style2)
}
}
}
//设置列宽
if (columnwidth != null)
{
for (int i = 0i <table.Columns.Counti++)
{
cell.SetColumnWidth(i, Convert.ToDouble(columnwidth[i].ToString("0")))
}
}
//保存excel表格
wb.Save(path)
System.Diagnostics.Process.Start(path)
Vue.js是一个前端JavaScript框架,它需要在页宽搜面中引入其主文件,通神坦常是 vue.min.js 或 vue.js。在引入之后,才能使用 Vue.js 的所有功能,包括实例化一个 Vue 对象。因此,在实例化之游巧桐前必须引入 Vue 的 core 文件。引用路径不亏启对,铅空野需要使用相对的绝对路径,如include __DIR__ . '/../../Component/PHPExcel.php';
其中 __DIR__ 是ExcelController这个文件所在槐喊的目录
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)