C# 用openxml做excel报表怎么做。excel有模板。查询的数据填充到模板指定的单元格内
2个回答
展开全部
如果EXCEL03格式的,用NPOI
public string GenerationToExcel(string path,string tempPath)
{
HSSFWorkbook workBook = new HSSFWorkbook(new FileStream(@tempPath, FileMode.Open, FileAccess.Read));
HSSFSheet sheet = workBook.GetSheet("Detail");
HSSFRow row = null;
List<LogisticsReportEntity> easCes = DataFacade<DLogictiscReport>.CreateProvider().getLogisticsReport();
int rowNum = 0;
HSSFCell cell =null; ;
HSSFCellStyle dateTimeCellStyle = workBook.CreateCellStyle();
HSSFDataFormat format = workBook.CreateDataFormat();
dateTimeCellStyle.DataFormat = format.GetFormat("mm/dd/yy");
foreach (LogisticsReportEntity o in easCes)
{
rowNum++;
row = sheet.CreateRow(rowNum);
int cNum = 0;
row.CreateCell(cNum++).SetCellValue(o.Status);
row.CreateCell(cNum++).SetCellValue(o.ReasonCode);
row.CreateCell(cNum++).SetCellValue(o.CustomerCode);
row.CreateCell(cNum++).SetCellValue(o.CustomerName);
row.CreateCell(cNum++).SetCellValue(o.TranNum);
row.CreateCell(cNum++).SetCellValue(o.CustRef);
}
string tempFileId = DateTime.Now.ToString("yyyyMMddHHmmss") + WebCom.RandomnAlpha(4);
FileStream file = new FileStream(path + tempFileId + ".xls", FileMode.Create);
workBook.Write(file);
file.Close();
return tempFileId;
public string GenerationToExcel(string path,string tempPath)
{
HSSFWorkbook workBook = new HSSFWorkbook(new FileStream(@tempPath, FileMode.Open, FileAccess.Read));
HSSFSheet sheet = workBook.GetSheet("Detail");
HSSFRow row = null;
List<LogisticsReportEntity> easCes = DataFacade<DLogictiscReport>.CreateProvider().getLogisticsReport();
int rowNum = 0;
HSSFCell cell =null; ;
HSSFCellStyle dateTimeCellStyle = workBook.CreateCellStyle();
HSSFDataFormat format = workBook.CreateDataFormat();
dateTimeCellStyle.DataFormat = format.GetFormat("mm/dd/yy");
foreach (LogisticsReportEntity o in easCes)
{
rowNum++;
row = sheet.CreateRow(rowNum);
int cNum = 0;
row.CreateCell(cNum++).SetCellValue(o.Status);
row.CreateCell(cNum++).SetCellValue(o.ReasonCode);
row.CreateCell(cNum++).SetCellValue(o.CustomerCode);
row.CreateCell(cNum++).SetCellValue(o.CustomerName);
row.CreateCell(cNum++).SetCellValue(o.TranNum);
row.CreateCell(cNum++).SetCellValue(o.CustRef);
}
string tempFileId = DateTime.Now.ToString("yyyyMMddHHmmss") + WebCom.RandomnAlpha(4);
FileStream file = new FileStream(path + tempFileId + ".xls", FileMode.Create);
workBook.Write(file);
file.Close();
return tempFileId;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |