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

推荐订阅源

博客园_首页
Microsoft Security Blog
Microsoft Security Blog
云风的 BLOG
云风的 BLOG
B
Blog
The Register - Security
The Register - Security
L
LangChain Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
N
Netflix TechBlog - Medium
F
Full Disclosure
The GitHub Blog
The GitHub Blog
Recorded Future
Recorded Future
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Blog — PlanetScale
Blog — PlanetScale
Jina AI
Jina AI
美团技术团队
宝玉的分享
宝玉的分享
Hugging Face - Blog
Hugging Face - Blog
阮一峰的网络日志
阮一峰的网络日志
G
Google Developers Blog
大猫的无限游戏
大猫的无限游戏
S
SegmentFault 最新的问题
D
DataBreaches.Net
Martin Fowler
Martin Fowler
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Google DeepMind News
Google DeepMind News
WordPress大学
WordPress大学
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - Franky
The Cloudflare Blog
博客园 - 【当耐特】
U
Unit 42
月光博客
月光博客
T
The Blog of Author Tim Ferriss
博客园 - 叶小钗
博客园 - 聂微东
I
InfoQ
B
Blog RSS Feed
Apple Machine Learning Research
Apple Machine Learning Research
Cyberwarzone
Cyberwarzone
V
V2EX
S
Securelist
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
S
Security @ Cisco Blogs
PCI Perspectives
PCI Perspectives
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
H
Heimdal Security Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
The Hacker News
The Hacker News
D
Darknet – Hacking Tools, Hacker News & Cyber Security
T
Tor Project blog

博客园 - 流云之心

招人啦 - 前端,后台开发专家 为什么不给程序员配好电脑 [翻译] SQL Server中对XML操作 开发常用小工具介绍 设计模式一 - Simple Factory, Factory Method, Abstract Factory以及Builder模式简述 强制休息程序 - EyeGuardian 眼睛守护者 Beta测试版 定时计划任务方案比较以及通过脚本创建计划任务(SchTasks命令) javascript 将页面上的Table导出保存为Excel (无格式) - 流云之心 Excel Programming (C# + VBA) Part III 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 II
流云之心 · 2007-12-04 · via 博客园 - 流云之心

2.     Step 2 Generate an Excel template to fill with source data in C#

a.       Create excel application object

            Microsoft.Office.Interop.Excel.Application xlsApp = null;

            Workbook wb
=null;
           

b.      Open the template and SaveCopyAs a new temporary template file name

     fileName= templatePath + @"\template.xls";
                 excelFileName 
= tempFileName + "_template.xls";
                 tempFileName
= tempFileName + "_template_Temp.xls";
                
                xlsApp 
= new ApplicationClass();
                wb 
= xlsApp.Workbooks.Open(fileName, 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);

                wb.SaveCopyAs(tempFileName);

c.       Close the template and open the new temporary file

                wb.Close(false, Type.Missing, Type.Missing);
                xlsApp.Quit();
                 wb 
= xlsApp.Workbooks.Open(tempFileName, 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);

d.      Get master data from database and fill in each cell and set, validation lock property properly based on requirement.

ws = (Worksheet)wb.Worksheets[DataSourceSheet];
                LoadDataSource(ws, wb, beginDate, endDate);
.


private void LoadDataSource(Worksheet ws, Workbook wb, DateTime beginDate, DateTime endDate)
        
{
            DataSet ds 
= SqlHelper.ExecuteDataset(connnectionString, CommandType.Text, "");
            
            
//Generate the Base Info
            ws.get_Range("A1",System.Type.Missing).Value2 = 0//Check flag
            ws.get_Range("A4",System.Type.Missing).Value2 = beginDate.ToString("yyyy-MM-dd");
            ws.get_Range(
"A5",System.Type.Missing).Value2 = endDate.ToString("yyyy-MM-dd");
            ws.get_Range(
"A6",System.Type.Missing).Value2 = beginDate.ToString(PlanDateFormat);
            ws.get_Range(
"A7",System.Type.Missing).Value2 = _templatetype;

            LoadActionStatus(wb, ws,  ds.Tables[
0]);
            LoadPromotionType(wb, ws,  ds.Tables[
0]);

            LoadUserDataSource(wb, ws, beginDate.ToString(PlanDateFormat));

            LoadCategoryDataSource(ws);

            
//ws.Visible = XlSheetVisibility.xlSheetVisible;
        }



        
private void LoadMaterialDataSource(Worksheet ws)
        
{
            
string sql = "select MaterialCode, EnglighShortName as MaterialName from Material";
            
string conn = ConfigurationSettings.AppSettings["ConnString"];
            Range rng 
= ws.get_Range("Q1",System.Type.Missing);
            QueryTable qt 
= ws.QueryTables.Add("OLEDB;Provider=SQLOLEDB.1;" + conn, rng, sql);
            qt.Refresh(System.Type.Missing);
            qt.Name 
= "Material";
        }


        
private void LoadCategoryDataSource(Worksheet ws)
        
{
            
string sql = "SELECT CategoryID, CategoryNameEn FROM Category WHERE Status = 3";
            
string conn = ConfigurationSettings.AppSettings["ConnString"];
            Range rng 
= ws.get_Range("W1",System.Type.Missing);
            QueryTable qt 
= ws.QueryTables.Add("OLEDB;Provider=SQLOLEDB.1;" + conn, rng, sql);
            qt.Refresh(System.Type.Missing);
            qt.Name 
= "Category";
        }

e.       Protected worksheets and workbook based on requirement

          ws = (Worksheet) wb.Worksheets[SummarySheet];

            ws.Protect(TemplatePassword,System.Type.Missing,System.Type.Missing,System.Type.Missing,System.Type.Missing,System.Type.Missing,System.Type.Missing,System.Type.Missing,System.Type.Missing,System.Type.Missing,System.Type.Missing,System.Type.Missing,System.Type.Missing,System.Type.Missing,System.Type.Missing, System.Type.Missing);

           wb.Protect(TemplatePassword,System.Type.Missing, System.Type.Missing);

f.      Save the temporary file as the final template name

            wb.SaveCopyAs(excelFileName);                  

g.       Close the template and release the excel resource

            if (wb!=null)

            
{

                  wb.Close(
false, Type.Missing, Type.Missing);

            }


            
if(xlsApp != null

            
{

                  xlsApp.Quit();

            }


            
//Remove the temporary file

            System.IO.File.Delete(tempFileName);   

.          Step 3 Download the template from web site

4.       Step 4 Fill in the template and verify the data

a.       User fills in the data according to the description: list validation, free typing in, popup form etc.

b.      Click the validation button in the sheet and validate the dat

5.       Step 5 Upload the template to the web site