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

推荐订阅源

Apple Machine Learning Research
Apple Machine Learning Research
Recent Announcements
Recent Announcements
IT之家
IT之家
人人都是产品经理
人人都是产品经理
G
Google Developers Blog
Microsoft Azure Blog
Microsoft Azure Blog
博客园_首页
大猫的无限游戏
大猫的无限游戏
U
Unit 42
罗磊的独立博客
博客园 - Franky
WordPress大学
WordPress大学
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
M
MIT News - Artificial intelligence
SecWiki News
SecWiki News
V
Vulnerabilities – Threatpost
P
Privacy International News Feed
P
Palo Alto Networks Blog
F
Fortinet All Blogs
P
Proofpoint News Feed
博客园 - 叶小钗
C
CERT Recently Published Vulnerability Notes
T
Tor Project blog
Spread Privacy
Spread Privacy
S
Securelist
C
Cisco Blogs
I
Intezer
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Cyberwarzone
Cyberwarzone
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
P
Privacy & Cybersecurity Law Blog
宝玉的分享
宝玉的分享
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Engineering at Meta
Engineering at Meta
S
Schneier on Security
C
CXSECURITY Database RSS Feed - CXSecurity.com
GbyAI
GbyAI
T
Troy Hunt's Blog
T
Threatpost
博客园 - 司徒正美
Y
Y Combinator Blog
Hugging Face - Blog
Hugging Face - Blog
AWS News Blog
AWS News Blog
T
The Blog of Author Tim Ferriss
G
GRAHAM CLULEY
N
Netflix TechBlog - Medium
酷 壳 – CoolShell
酷 壳 – CoolShell
Google DeepMind News
Google DeepMind News
Know Your Adversary
Know Your Adversary
S
SegmentFault 最新的问题

博客园 - Caviare

前台优化法则(YSlow) ASP.NET MVC源代码 启用IIS的Gzip压缩功能 web.sitemap Dynamic Generation SQL字符正则匹配 委托应用 判断大陆IPAddress 迭代器和排序基本使用 Bertrand Meyer提出的设计模式的原则 - Caviare - 博客园 Web.cofig详解[转] UpdatePanel Control [转老赵博客] .Net环境下的缓存技术介绍 (转) [转]webservice和remoting在分布式程序中的应用 sql2005备份在sql2000中恢复 Excel WorkBook操作例 温故知新-Excel操作类 SQL collation设置 一张类的访问权限图,帮您加深概念 [转]您可能不知道的Asp.Net2.0技巧
WorkBook操作实例
Caviare · 2007-11-30 · via 博客园 - Caviare

程序目的:EXCEL文件存放数据,根据提供的模板,生成相应的word文件,每条数据生成一页数据。

Excel操作:取数据

using System;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using Excel = Microsoft.Office.Interop.Excel;

namespace WorkBookForHKAccountDoc
{
    
public class ExcelOperation
    
{
        
public delegate void ErrorEventHandler(object sender, OnErrorEventArgs e);
        
public event ErrorEventHandler OnError = null;

        
public delegate void InfoEventHandler(object sender, OnPrintInfoEventArgs e);
        
public event InfoEventHandler OnPrintInfo = null;

        
获取EXCEL中用户信息列表

    }

}

数据结构:

using System;
using System.Collections.Generic;
using System.Text;

namespace WorkBookForHKAccountDoc
{
    
public class AccountInfo
    
{
        
public string txtClient_Main_Account;
        
public string txtClient_Properity;
        
public string txtClient_Sub_Account;
        
public string txtShort_Name;
        
public string txtChinese_Name;
        
public string txtOpen_Date;
        
public string txtStatus;
    }

}

Word文件操作:

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Office.Interop.Word;

namespace WorkBookForHKAccountDoc
{
    
public class WordOperation
    
{
        
public delegate void ErrorEventHandler(object sender, OnErrorEventArgs e);
        
public event ErrorEventHandler OnError = null;
        
public delegate void InfoEventHandler(object sender, OnPrintInfoEventArgs e);
        
public event InfoEventHandler OnPrintInfo = null;

        
private int intCopyNum = 1;
        
        

        
生成用户信息文档

        
生成用户ID表格文档

        
CommonFunctions

    }

}

MAINFORM:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WorkBookForHKAccountDoc
{
    
public partial class MainForm : Form
    
{
        
public MainForm()
        
{
            InitializeComponent();
        }


        
private void MainForm_Load(object sender, EventArgs e)
        
{
            initializeComBox();
        }

        
private void btnXlsFileUp_Click(object sender, EventArgs e)
        
{
            OpenFileDialog file 
= new OpenFileDialog();
            file.Title 
= "选择Excel资源";
            file.Filter 
= "xls files(*.xls)|*.xls" +
                            
"|All files(*.*)|*.*";
            
if (file.ShowDialog() == DialogResult.OK)
            
{
                txtXlsFilePathName.Text 
= file.FileName;
            }

            file.Dispose();
        }

        
private void btnXlsFileUp2_Click(object sender, EventArgs e)
        
{
            OpenFileDialog file 
= new OpenFileDialog();
            file.Title 
= "选择Excel资源";
            file.Filter 
= "xls files(*.xls)|*.xls" +
                            
"|All files(*.*)|*.*";
            
if (file.ShowDialog() == DialogResult.OK)
            
{
                txtXlsFilePathName2.Text 
= file.FileName;
            }

            file.Dispose();
        }

        
private void btnDocFileUp_Click(object sender, EventArgs e)
        
{
            OpenFileDialog file 
= new OpenFileDialog();
            file.Title 
= "选择Doc文档";
            file.Filter 
= "doc files(*.doc)|*.doc" +
                            
"|All files(*.*)|*.*";
            
if (file.ShowDialog() == DialogResult.OK)
            
{
                txtDocFilePathName.Text 
= file.FileName;
            }

            file.Dispose();
        }

        
private void btnDocAccountFileUp_Click(object sender, EventArgs e)
        
{
            OpenFileDialog file 
= new OpenFileDialog();
            file.Title 
= "选择Doc文档";
            file.Filter 
= "doc files(*.doc)|*.doc" +
                            
"|All files(*.*)|*.*";
            
if (file.ShowDialog() == DialogResult.OK)
            
{
                
this.txtDocAccountFilePathName.Text = file.FileName;
            }

            file.Dispose();
        }


        
private void btnGenerateAccInfoDocs_Click(object sender, EventArgs e)
        
{
            
if (!validateTag1())
            
{
                
return;
            }

            
try
            
{
                ExcelOperation xlsOp 
= new ExcelOperation();
                xlsOp.OnPrintInfo 
+= new ExcelOperation.InfoEventHandler(OnPrintInfo);
                xlsOp.OnError 
+= new ExcelOperation.ErrorEventHandler(OnError);
                System.Collections.Generic.List
<AccountInfo> list = xlsOp.getAccountList(this.txtXlsFilePathName.Text);
                
int intTmp = 1;
                
if (comboBox1.SelectedIndex > 0)
                
{
                    intTmp 
= Convert.ToInt32(this.comboBox1.SelectedItem);
                }

                WordOperation docOp 
= new WordOperation();
                docOp.OnError 
+= new WordOperation.ErrorEventHandler(OnError);
                docOp.OnPrintInfo 
+= new WordOperation.InfoEventHandler(OnPrintInfo);
                
object objDocMouldFileAccInfo = txtDocFilePathName.Text;
                docOp.generateDocumentDoc(list, GetConfigValue(
"strSaveAccountInfoDocPath"), objDocMouldFileAccInfo,intTmp);
                MessageBox.Show(
"执行完毕!");
            }

            
catch (Exception ex)
            
{
                OnError(
thisnew OnErrorEventArgs("", ex));
            }

        }

        
private void btnGenerateAccIDDocs_Click(object sender, EventArgs e)
        
{
            
if (!validateTag2())
            
{
                
return;
            }

            
try
            
{
                ExcelOperation xlsOp 
= new ExcelOperation();
                xlsOp.OnPrintInfo 
+= new ExcelOperation.InfoEventHandler(OnPrintInfo);
                xlsOp.OnError 
+= new ExcelOperation.ErrorEventHandler(OnError);
                System.Collections.Generic.List
<AccountInfo> list = xlsOp.getAccountList(this.txtXlsFilePathName2.Text);
                WordOperation docOp 
= new WordOperation();
                docOp.OnError 
+= new WordOperation.ErrorEventHandler(OnError);
                docOp.OnPrintInfo 
+= new WordOperation.InfoEventHandler(OnPrintInfo);
                
object objDocMouldFileAccID = txtDocAccountFilePathName.Text;
                docOp.generateTableDoc(list, GetConfigValue(
"strSaveAccountIDDocPath"), objDocMouldFileAccID);
                MessageBox.Show(
"执行完毕!");
            }

            
catch (Exception ex)
            
{
                OnError(
thisnew OnErrorEventArgs("", ex));
            }

        }


        
void OnError(object sender, OnErrorEventArgs e)
        
{
            listBox1.Items.Add(e.AccountID 
+ " | " + e.InnerException.Message);
            
this.Refresh();
        }

        
void OnPrintInfo(object sender, OnPrintInfoEventArgs e)
        
{
            listBox1.Items.Add(e.StrEventInfo);
            listBox1.SelectedIndex 
= listBox1.Items.Count - 1;
            
this.Refresh();
        }

        
void initializeComBox()
        
{
            
object objComBoxItem = "--用户信息拷贝数--";
            
this.comboBox1.Items.Add(objComBoxItem);
            
for (int i = 1; i <= 10; i++)
            
{
                objComBoxItem 
= i;
                
this.comboBox1.Items.Add(objComBoxItem);
            }

            comboBox1.SelectedIndex 
= 0;
        }

        
bool validateTag1()
        
{
            
if (this.txtDocAccountFilePathName.Text == "" ||  txtXlsFilePathName.Text == "")
            
{
                MessageBox.Show(
"请选择需要的文件!");
                
return false;
            }

            
else
            
{
                
return true;
            }

        }

        
bool validateTag2()
        
{
            
if ( this.txtDocAccountFilePathName.Text == "" || txtXlsFilePathName2.Text == "")
            
{
                MessageBox.Show(
"请选择需要的文件!");
                
return false;
            }

            
else
            
{
                
return true;
            }

        }

        
string GetConfigValue(string strCfgName)
        
{
            
string strRet = System.Configuration.ConfigurationSettings.AppSettings[strCfgName];
            
if (!strRet.EndsWith(@"\"))
            
{
                strRet 
= strRet + @"\";
            }

            
return strRet;
        }


        
    }


}