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

推荐订阅源

月光博客
月光博客
Microsoft Security Blog
Microsoft Security Blog
T
Threatpost
D
DataBreaches.Net
B
Blog RSS Feed
GbyAI
GbyAI
T
The Blog of Author Tim Ferriss
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
N
Netflix TechBlog - Medium
O
OpenAI News
Webroot Blog
Webroot Blog
Stack Overflow Blog
Stack Overflow Blog
Recent Announcements
Recent Announcements
Google Online Security Blog
Google Online Security Blog
SecWiki News
SecWiki News
H
Help Net Security
Forbes - Security
Forbes - Security
N
News and Events Feed by Topic
aimingoo的专栏
aimingoo的专栏
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
腾讯CDC
B
Blog
H
Heimdal Security Blog
博客园 - 三生石上(FineUI控件)
C
CERT Recently Published Vulnerability Notes
L
Lohrmann on Cybersecurity
G
Google Developers Blog
Scott Helme
Scott Helme
C
CXSECURITY Database RSS Feed - CXSecurity.com
罗磊的独立博客
V
Visual Studio Blog
L
LINUX DO - 热门话题
T
Threat Research - Cisco Blogs
T
The Exploit Database - CXSecurity.com
F
Full Disclosure
C
Cisco Blogs
The Last Watchdog
The Last Watchdog
Security Archives - TechRepublic
Security Archives - TechRepublic
F
Fortinet All Blogs
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Google DeepMind News
Google DeepMind News
S
Security Affairs
P
Privacy & Cybersecurity Law Blog
S
Secure Thoughts
V
V2EX
雷峰网
雷峰网
Security Latest
Security Latest
H
Hacker News: Front Page
TaoSecurity Blog
TaoSecurity Blog
M
MIT News - Artificial intelligence

博客园 - ★金★

导出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();