惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

P
Privacy International News Feed
MongoDB | Blog
MongoDB | Blog
WordPress大学
WordPress大学
小众软件
小众软件
H
Hacker News: Front Page
S
Securelist
S
SegmentFault 最新的问题
Jina AI
Jina AI
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
阮一峰的网络日志
阮一峰的网络日志
G
GRAHAM CLULEY
P
Palo Alto Networks Blog
博客园 - 司徒正美
量子位
罗磊的独立博客
大猫的无限游戏
大猫的无限游戏
Cyberwarzone
Cyberwarzone
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
P
Privacy & Cybersecurity Law Blog
月光博客
月光博客
V
Visual Studio Blog
C
CERT Recently Published Vulnerability Notes
爱范儿
爱范儿
T
Threat Research - Cisco Blogs
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Apple Machine Learning Research
Apple Machine Learning Research
T
The Exploit Database - CXSecurity.com
T
Tenable Blog
L
LINUX DO - 热门话题
MyScale Blog
MyScale Blog
Hugging Face - Blog
Hugging Face - Blog
M
MIT News - Artificial intelligence
腾讯CDC
NISL@THU
NISL@THU
A
Arctic Wolf
Scott Helme
Scott Helme
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
宝玉的分享
宝玉的分享
T
Tailwind CSS Blog
L
LINUX DO - 最新话题
The GitHub Blog
The GitHub Blog
Help Net Security
Help Net Security
C
Check Point Blog
O
OpenAI News
D
DataBreaches.Net
I
InfoQ
N
News and Events Feed by Topic
S
Security @ Cisco Blogs
D
Darknet – Hacking Tools, Hacker News & Cyber Security
F
Fortinet All Blogs

博客园 - ★金★

导出EXCEL table变宽格式 IE11兼容性设定 C#获取多个相同name值 DIV左右行 Jquery绑定Select下拉菜单 SQL中多项合并时请加ISNULL Repeater中绑定下拉菜单的2种方法 WebForm设置URL路由后要照顾好之前的连接 Repeater中获取HTML select 值 博文阅读密码验证 - 博客园 Firefox中不支持parentElement用parentNode取代 jquery给span赋值的时候出现firefox不兼容 jquery表单验证增加确认及可选不需要验证的方法 javascript可用数组取代case格式化字符 display和visibility的区别 SQL中Replace替换引号 javascript动态添加删除行后行内计算及取值 取代RadioButtonList及RadioButton方法
NPOI生成Excel
★金★ · 2011-04-22 · via 博客园 - ★金★
            //创建工作表
            HSSFWorkbook workbook = new HSSFWorkbook();
            Sheet sheet = workbook.CreateSheet("Sheet1");

            //创建表头
            Row headerRow = sheet.CreateRow(1);
            for (int i = 0; i < strField.Length; i++)
            {
                headerRow.CreateCell(i).SetCellValue(strField[i]);
            }

            //创建内容
            int rowIndex = 2;
            Row dataRow = sheet.CreateRow(rowIndex);
            for (int i = 0; i < list.Count;i++ )
            {
                Cell newCell = dataRow.CreateCell(i);
                newCell.SetCellValue(list[i]);
            }
            rowIndex++;

            FileStream file = new FileStream(@"c:/test.xls", FileMode.Create);
            workbook.Write(file);
            file.Close();


DataTable生成EXCEL:

public static void getExcel(DataTable dt)
        {
            NPOI.HSSF.UserModel.HSSFWorkbook book = new NPOI.HSSF.UserModel.HSSFWorkbook();
            NPOI.SS.UserModel.Sheet sheet = book.CreateSheet("test_01");
            NPOI.SS.UserModel.Row row = sheet.CreateRow(0);

            //创建表头
            for (int i = 0; i < dt.Columns.Count; i++)
            {
                row.CreateCell(i).SetCellValue(dt.Columns[i].ColumnName);
            }

            //创建内容
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                NPOI.SS.UserModel.Row row2 = sheet.CreateRow(i + 1);
                for (int j = 0; j < dt.Columns.Count; j++)
                    row2.CreateCell(j).SetCellValue(dt.Rows[i][j].ToString());
            }


            //写入到客户端
            FileStream file = new FileStream(@"c:/test2.xls", FileMode.Create);
            book.Write(file);
            file.Close();
            book.Dispose();
        }

读取excel模板生成EXCEL:

            FileStream file = new FileStream(@"c:/book1.xls", FileMode.Open, FileAccess.Read);

            HSSFWorkbook hssfworkbook = new HSSFWorkbook(file);
            Sheet sheet1 = hssfworkbook.GetSheet("Sheet1");
            sheet1.GetRow(1).GetCell(1).SetCellValue(200200);
            sheet1.GetRow(2).GetCell(1).SetCellValue(300);
            sheet1.GetRow(3).GetCell(1).SetCellValue(500050);
            sheet1.GetRow(4).GetCell(1).SetCellValue(8000);
            sheet1.GetRow(5).GetCell(1).SetCellValue(110);
            sheet1.GetRow(6).GetCell(1).SetCellValue(100);
            sheet1.GetRow(7).GetCell(1).SetCellValue(200);
            sheet1.GetRow(8).GetCell(1).SetCellValue(210);
            sheet1.GetRow(9).GetCell(1).SetCellValue(2300);
            sheet1.GetRow(10).GetCell(1).SetCellValue(240);
            sheet1.GetRow(11).GetCell(1).SetCellValue(180123);
            sheet1.GetRow(12).GetCell(1).SetCellValue(150);

            //Force excel to recalculate all the formula while open
            sheet1.ForceFormulaRecalculation = true;
            FileStream file2 = new FileStream(@"c:/testadsafd.xls", FileMode.Create);
            hssfworkbook.Write(file2);
            file.Close();
            file2.Close();