当前位置:网站首页>ASP.NET 获取数据库的数据并写入到excel表格中
ASP.NET 获取数据库的数据并写入到excel表格中
2022-08-04 00:47:00 【CSDN问答】
问题遇到的现象和发生背景
从数据库读取出数据,并且把数据写入到excel表格对应的列中
问题相关代码,请勿粘贴截图
string fileDir = System.Web.HttpContext.Current.Server.MapPath("~/UI/BQ/Temp/测试报表.xlsx"); FileStream file = new FileStream(fileDir, FileMode.Open, FileAccess.Read); //创建HSSFWorkbook对象 XSSFWorkbook hssfworkbook = new XSSFWorkbook(file); //创建HSSFSheet对象 NPOI.SS.UserModel.ISheet sheet = hssfworkbook.GetSheetAt(0); //ISheet sheet = hssfworkbook.GetSheet("sheet1"); System.Collections.IEnumerator rows = sheet.GetRowEnumerator(); DataTable dataTable; CustomSqlSection customSqlSection = Gateway.Default.FromCustomSql(sql); dataTable = customSqlSection.ToDataSet().Tables[0]; for (int i = 2; i < dataTable.Rows.Count; i++) { sheet.GetRow(i).GetCell(0).SetCellValue(dataTable.Rows[i - 2]["VIN"].ToString()); sheet.GetRow(i).GetCell(1).SetCellValue(dataTable.Rows[i - 2]["CAR_TYPE_CODE"].ToString()); sheet.GetRow(i).GetCell(2).SetCellValue(dataTable.Rows[i - 2]["BAD_DESC"].ToString()); sheet.GetRow(i).GetCell(3).SetCellValue(dataTable.Rows[i-2]["Model"].ToString()); sheet.GetRow(i).GetCell(4).SetCellValue(dataTable.Rows[i - 2]["LEVEL_VAL"].ToString()); sheet.GetRow(i).GetCell(5).SetCellValue(dataTable.Rows[i - 2]["HD2"].ToString()); sheet.GetRow(i).GetCell(6).SetCellValue(dataTable.Rows[i - 2]["OTHER_DES"].ToString()); }运行结果及报错内容
写入的时候这个循环体内的数据报错: sheet.GetRow(i).GetCell(0).SetCellValue(dataTable.Rows[i - 2]["VIN"].ToString());//
{"EXCEPTION":"文件写入数据异常:未将对象引用设置到对象的实例。"}

我的解答思路和尝试过的方法
给表格增加列名

我想要达到的结果
从数据库读取出数据,并且把数据写入到excel表格对应的列中
边栏推荐
- 搭建好pytorch环境后,pip和conda指令不能用
- jmeter distributed stress test
- Using matlab to solve the linear optimization problem based on matlab dynamic model of learning notes _11 】 【
- 2022年8月份DAMA-CDGA/CDGP数据治理认证招生简章
- 手撕Nacos源码,今日撕服务端源码
- typescript54 - generic constraints
- jmeter分布式压测
- 微服务的简单介绍
- 身为程序员的我们如何卷死别人?破局重生。
- Justin Sun: Web3.0 and the Metaverse will assist mankind to enter the online world more comprehensively
猜你喜欢

typescript54-泛型约束

ENS域名注册量创历史新高 逆市增长之势?光环之下存在炒作风险

轻量级网络整理及其在Yolov5上的实现

win10+cuda11.7+pytorch1.12.0 installation

js函数防抖和函数节流及其使用场景

Read FastDFS in one article

typescript53 - generic constraints
![2022-08-03:以下go语言代码输出什么?A:2;B:3;C:1;D:0。 package main import “fmt“ func main() { slice := []i](/img/a9/6de3c2bae92d09b13b1c36e01f86c2.png)
2022-08-03:以下go语言代码输出什么?A:2;B:3;C:1;D:0。 package main import “fmt“ func main() { slice := []i

typescript52-简化泛型函数调用

Salesforce's China business may see new changes, rumors may be closing
随机推荐
MATLAB三维绘图命令plot3入门
Nanoprobes Alexa Fluor 488 FluoroNanogold 偶联物
typescript57 - Array generic interface
VR全景拍摄线上展馆,3D全景带你沉浸体验
建木DevOps流程的快速运用
Salesforce的中国区业务可能出现新变化,传言可能正在关闭
[Miscellaneous] How to install the specified font into the computer and then use the font in the Office software?
咱们500万条数据测试一下,如何合理使用索引加速?
做项目一定用得到的NLP资源【分类版】
SQL优化的一些建议,希望可以帮到和我一样被SQL折磨的你
电子制造企业部署WMS仓储管理系统的好处是什么
搭建好pytorch环境后,pip和conda指令不能用
114. How to find the cause of Fiori Launchpad routing error by single-step debugging
BioVendor人Clara细胞蛋白(CC16)Elisa试剂盒检测步骤
jmeter distributed stress test
typescript48 - type compatibility between functions
How to find the cause of Fiori Launchpad routing errors by single-step debugging
教你如何定位不合理的SQL?并优化之
corn表达式 具体详解与案例
typescript52 - simplify generic function calls