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

推荐订阅源

Engineering at Meta
Engineering at Meta
T
Threatpost
P
Palo Alto Networks Blog
NISL@THU
NISL@THU
O
OpenAI News
Project Zero
Project Zero
G
GRAHAM CLULEY
P
Privacy International News Feed
A
Arctic Wolf
Microsoft Azure Blog
Microsoft Azure Blog
H
Help Net Security
M
MIT News - Artificial intelligence
T
Threat Research - Cisco Blogs
S
Security @ Cisco Blogs
Google DeepMind News
Google DeepMind News
B
Blog RSS Feed
D
Docker
aimingoo的专栏
aimingoo的专栏
博客园 - 【当耐特】
N
Netflix TechBlog - Medium
云风的 BLOG
云风的 BLOG
雷峰网
雷峰网
W
WeLiveSecurity
P
Proofpoint News Feed
腾讯CDC
Cloudbric
Cloudbric
S
Secure Thoughts
C
Check Point Blog
博客园 - Franky
T
The Exploit Database - CXSecurity.com
T
Troy Hunt's Blog
GbyAI
GbyAI
Security Archives - TechRepublic
Security Archives - TechRepublic
Application and Cybersecurity Blog
Application and Cybersecurity Blog
月光博客
月光博客
C
Cyber Attacks, Cyber Crime and Cyber Security
I
Intezer
TaoSecurity Blog
TaoSecurity Blog
L
Lohrmann on Cybersecurity
V
Visual Studio Blog
F
Fortinet All Blogs
博客园 - 叶小钗
C
CXSECURITY Database RSS Feed - CXSecurity.com
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Recorded Future
Recorded Future
C
Cisco Blogs
博客园 - 司徒正美
Stack Overflow Blog
Stack Overflow Blog
Y
Y Combinator Blog
Apple Machine Learning Research
Apple Machine Learning Research

博客园 - chinachen

查看DLL 版本 平台 x86 x64 MS SQL2008 数据库备份(收集) android 使用sqlite几种方式。 C# 接口 索引 属性 实质及应用 (收集) get set 用法总结 (收集) MVC 资料收集(一) windows运行命令大全 Html:meta标签的奥妙 (收集) - chinachen - 博客园 ASP.NET抓取页面并分析页面数据的研究与探讨。 C#中indexof和substring函数用法 (收集) - chinachen - 博客园 BlogEngine 深入研究(一) 开篇 ASP.NET实现回调服务器方法 (收集) 统一过程,敏捷过程,微软过程(收集) HTTP服务器状态代码定义(Status Code Definitions)(收集) Lambda 表达式 源自MSDN C# 参考之方法参数关键字:params、ref及out (收集) nchar,char,varchar 与nvarchar区别 (收集) - chinachen 抽象类与接口区别 (收集) virtual 与 Abstract 区别
多个表 导出EXCEL 代码 (分享)
chinachen · 2010-02-25 · via 博客园 - chinachen

多个表 导出EXCEL 

 public void ExportExcel(DataSet dsExcel)
        {

            DataSet ds 

= dsExcel;
            
if (ds == nullreturn;string saveFileName = "";
            
bool fileSaved = false;
            SaveFileDialog saveDialog 
= new SaveFileDialog();
            saveDialog.DefaultExt 
= "xls";
            saveDialog.Filter 
= "Excel文件|*.xls";
            saveDialog.FileName 
= "招生数据备份";
            saveDialog.ShowDialog();
            saveFileName 
= saveDialog.FileName;
            
if (saveFileName.IndexOf(":"< 0return//被点了取消 

            Excel.Application xlApp 
= new Excel.Application();if (xlApp == null)
            {
                MessageBox.Show(
"无法创建Excel对象,可能您的机子未安装Excel");
                
return;
            }

            Excel.Workbooks workbooks 

= xlApp.Workbooks;
            
string[] tableName ="TB_Dic_ExamArea","TB_Dic_ExamArea_SpecialityKinds","TB_Dic_ExamRoom","TB_Dic_SpecialityFocus","TB_ExamAchievement","TB_SignUpStudents","TB_SignUpStudentsFamilyMember","TB_SignUpStudentsPayFee","TB_SignUpStudentsResume","TB_SignUpStudentsSpeciality","TB_SystemInfo","TB_Users"};

            Excel.Workbook workbook 

= workbooks.Add(Excel.XlWBATemplate.xlWBATWorksheet);
            
for (int a = 0; a < 12; a++)
            {
                Excel.Worksheet newWorksheet;
                newWorksheet 
= (Excel.Worksheet)workbook.Worksheets.Add(System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value);
                newWorksheet.Name 
= tableName[11-a];
            }
            
//
            proValue = 0;
            
for (int b = 0; b < 12; b++)
            {

                Excel.Worksheet worksheet 

= (Excel.Worksheet)workbook.Worksheets[b+1];//取得sheet1 
                
//写入字段 
                int cellNum = ds.Tables[b].Columns.Count;
                
for (int i = 0; i < cellNum; i++)
                {
                    worksheet.Cells[
1, i + 1= ds.Tables[b].Columns[i].ColumnName;

                    worksheet.get_Range(worksheet.Cells[

11 + i], worksheet.Cells[1 + ds.Tables[b].Rows.Count, 1 + i]).NumberFormatLocal = "@";
                }
                
//写入数值 

                
int rowNum = ds.Tables[b].Rows.Count;
                
for (int r = 0; r < rowNum; r++)
                {
                    
for (int i = 0; i < cellNum; i++)
                    {
                        worksheet.Cells[r 
+ 2, i + 1= ds.Tables[b].Rows[r][i].ToString();
                    }
                    System.Windows.Forms.Application.DoEvents();
                }
                Excel.Range rg 
= worksheet.get_Range(worksheet.Cells[22], worksheet.Cells[ds.Tables[b].Rows.Count + 12]);
                rg.NumberFormat 
= "00000000";
                proValue
++;
                progressBar1.PerformStep();
            }
            
if (saveFileName != "")
            {
                
try
                {
                    workbook.Saved 
= true;
                    workbook.SaveCopyAs(saveFileName);
                    fileSaved 
= true;
                }
                
catch (Exception ex)
                {
                    fileSaved 
= false;
                    MessageBox.Show(
"导出文件时出错,文件可能正被打开!\n" + ex.Message);
                }
            }
            
else
            {
                fileSaved 
= false;
            }
            xlApp.Quit();
            GC.Collect();
//强行销毁 
            if (fileSaved && System.IO.File.Exists(saveFileName)) System.Diagnostics.Process.Start(saveFileName); //打开EXCEL
            progressBar1.Value = 0;
        }

 代码