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

推荐订阅源

GbyAI
GbyAI
J
Java Code Geeks
雷峰网
雷峰网
WordPress大学
WordPress大学
宝玉的分享
宝玉的分享
云风的 BLOG
云风的 BLOG
V
Visual Studio Blog
V
Vulnerabilities – Threatpost
S
Securelist
The Hacker News
The Hacker News
The Register - Security
The Register - Security
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Help Net Security
Help Net Security
G
Google Developers Blog
Hugging Face - Blog
Hugging Face - Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
M
MIT News - Artificial intelligence
AI
AI
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
The GitHub Blog
The GitHub Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Schneier on Security
Schneier on Security
N
Netflix TechBlog - Medium
T
The Blog of Author Tim Ferriss
Google DeepMind News
Google DeepMind News
Hacker News - Newest:
Hacker News - Newest: "LLM"
H
Hacker News: Front Page
博客园 - 司徒正美
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
B
Blog
Microsoft Azure Blog
Microsoft Azure Blog
大猫的无限游戏
大猫的无限游戏
Security Latest
Security Latest
Engineering at Meta
Engineering at Meta
N
News and Events Feed by Topic
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
酷 壳 – CoolShell
酷 壳 – CoolShell
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
T
Threat Research - Cisco Blogs
U
Unit 42
V
V2EX
V2EX - 技术
V2EX - 技术
L
LINUX DO - 最新话题
aimingoo的专栏
aimingoo的专栏
Microsoft Security Blog
Microsoft Security Blog
Recorded Future
Recorded Future
P
Privacy & Cybersecurity Law Blog
美团技术团队
小众软件
小众软件
F
Fortinet All Blogs

博客园 - 流云之心

招人啦 - 前端,后台开发专家 为什么不给程序员配好电脑 [翻译] SQL Server中对XML操作 开发常用小工具介绍 设计模式一 - Simple Factory, Factory Method, Abstract Factory以及Builder模式简述 强制休息程序 - EyeGuardian 眼睛守护者 Beta测试版 定时计划任务方案比较以及通过脚本创建计划任务(SchTasks命令) javascript 将页面上的Table导出保存为Excel (无格式) - 流云之心 Excel Programming (C# + VBA) Part II Excel programming (C# + VBA) Part 1 Harry Potter - The Half-Blood Prince 转移阵地了,新地址:http://spaces.msn.com/members/PuGong 关于XMLHTTP object的OPEN方法 smart client优势在那里? (草稿) SQL Server的collation问题 Microsoft Interview Question links 转自http://blogs.msdn.com/chappell/archive/2004/07/20/189364.aspx MSN to expand free e-mail storage to 250MB 用 #inculde file = "../fiel" 报1031错误 用<!--include file = ../ --> 报错误1031
Excel Programming (C# + VBA) Part III
流云之心 · 2007-12-05 · via 博客园 - 流云之心
 

Step 6 Import the data in excel to database

a.       Create excel app object and open the uploaded file

            Microsoft.Office.Interop.Excel.Application xlsApp = new ApplicationClass();

            Workbook wb 
= xlsApp.Workbooks.Open(_filePath,Type.Missing,Type.Missing, Type.Missing,Type.Missing,Type.Missing,Type.Missing, Type.Missing,Type.Missing,Type.Missing,Type.Missing, Type.Missing,Type.Missing,Type.Missing,Type.Missing);

            wb.Unprotect(TemplatePassword);

b.      Save the upload file as a temporary file. Then close uploaded file and open the temporary file

           string tempFileName = _filePath.ToLower().Replace(".xls","_Temp.xls");      

            wb.Unprotect(TemplatePassword);

            wb.SaveCopyAs(tempFileName);

c.       Verify the data in template again in web application

            ReadDataSource((Worksheet)wb.Worksheets[DataSourceSheet], out branchID, out planDate, out startDate, out endDate, out iChecked, out templatetype);

           
if(!(iChecked == 1))

            
{

                returnVal 
= "Please verify the data before upload to the server!";

                  
throw new Exception(returnVal);

            }


            
if(templatetype.ToUpper() != _templatetype.ToUpper())

            
{

                  returnVal 
= "The version is not corrected, please verify the document and uploaded again";

                  
throw new Exception(returnVal);

            }


 ……

private void ReadDataSource(Worksheet ws, out string branchID, out string planDate, out DateTime startDate,out DateTime endDate, out int iChecked, out string templatetype)

      
{

            
string check = ws.get_Range("A1", System.Type.Missing).Text.ToString();

            branchID 
= ws.get_Range("A2", System.Type.Missing).Text.ToString();

            
string sDate = ws.get_Range("A4", System.Type.Missing).Text.ToString();

            
string eDate = ws.get_Range("A5", System.Type.Missing).Text.ToString();

            planDate 
= ws.get_Range("A6", System.Type.Missing).Text.ToString();

            templatetype 
= ws.get_Range("A7", System.Type.Missing).Text.ToString();

            startDate 
= DateTime.Parse(sDate);

            endDate 
= DateTime.Parse(eDate);

            
try

            
{

                  iChecked 
= Convert.ToInt16(check);

            }


            
catch

            
{

                  iChecked 
= 0;

            }


      }
    

d.      Read the data in the worksheet

            string territoryList = ws.get_Range("B"+ i.ToString(), System.Type.Missing).Text.ToString();

            
string territoryIDList = ws.get_Range("AB" + i.ToString(), System.Type.Missing).Text.ToString();

            
string category = ws.get_Range("E" + i.ToString(), System.Type.Missing).Text.ToString();

            
string categoryID = ws.get_Range("AE" + i.ToString(), System.Type.Missing).Text.ToString();

e.      Change the database based on data in excel sheet

            SqlHelper.ExecuteNonQuery(connnectionString, CommandType.Text, "insert into … ");                 

Summary: Objects used in this sample

a.       Excel.Application

                                                               i.      Application.Workbooks.Open

                                                             ii.      Quit

b.      Excel.Workbook

                                                               i.      SaveCopyAs

                                                             ii.      Unprotect

                                                            iii.      Worksheets

                                                           iv.      Protect

                                                             v.      .Names.Add

                                                           vi.      Close

c.       Excel.WorkSheet

                                                               i.      Unprotect

                                                             ii.      Protect

                                                            iii.      .Hyperlinks.Add

d.      Range

                                                               i.      Value2

                                                             ii.      Text

e.      Cell, Cells