嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元微信扫码支付:2 元
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
//创建SXSSFWorkbook对象
XSSFWorkbook xsfwb = new XSSFWorkbook();
SXSSFWorkbook wb = new SXSSFWorkbook(xsfwb,1000,true);
for(int i=0;i<5;i )
{
//创建sheet 并指定sheet的名字100
ISheet sheet1 = wb.CreateSheet("详细数据" i);
//新建style对象并设置样式属性
ICellStyle style1 = wb.CreateCellStyle();//样式
IFont font1 = wb.CreateFont();//字体
font1.FontName = "宋体";
font1.FontHeightInPoints = 11;
font1.Boldweight = (short)FontBoldWeight.Bold;
style1.SetFont(font1);//样式里的字体设置具体的字体样式
//创建第一行
IRow row0 = sheet1.CreateRow(0);
//创建第一行第一列并设置值
row0.CreateCell(0).SetCellValue("姓名");
//获取第一行第一列并设置样式
row0.GetCell(0).CellStyle = style1;
row0.CreateCell(1).SetCellValue("年龄");
row0.GetCell(1).CellStyle = style1;
row0.CreateCell(2).SetCellValue("地址");
row0.GetCell(2).CellStyle = style1;
row0.CreateCell(3).SetCellValue("性别");
row0.GetCell(3).CellStyle = style1;
foreach (DataItem item in bigData)
{
int item_index = bigData.IndexOf(item);
//从第二行开始
if (item_index <= 100000)
{
IRow rowi = sheet1.CreateRow(item_index 1);
rowi.CreateCell(0).SetCellValue(item.Name);
rowi.CreateCell(1).SetCellValue(item.Age);
rowi.CreateCell(2).SetCellValue(item.Address);
rowi.CreateCell(3).SetCellValue(item.Sex);
}
else
{
int ikk = item_index;
break;
}
//设置列宽度,256*字符数,因为单位是1/256个字符
//sheet1.SetColumnWidth(item_index, 256 * item.Address.Length * 4);
}
((SXSSFSheet)sheet1).flushRows();
}
try
{
//将内存中的数据写入磁盘
using (FileStream filestream = new FileStream(System.IO.Path.Combine(@"D:\", "qizhi.xlsx"), FileMode.Create))
{
wb.Write(filestream);
filestream.Close();
}
wb.Dispose();
wb.Close();
wb = null;
GC.Collect();
}
catch (Exception ex)
{
Console.Write(ex);
}
MessageBox.Show("导出完成");