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

推荐订阅源

The Last Watchdog
The Last Watchdog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
GbyAI
GbyAI
Y
Y Combinator Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
The GitHub Blog
The GitHub Blog
博客园_首页
小众软件
小众软件
I
InfoQ
J
Java Code Geeks
月光博客
月光博客
S
Secure Thoughts
Microsoft Security Blog
Microsoft Security Blog
V
Visual Studio Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Stack Overflow Blog
Stack Overflow Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
N
News and Events Feed by Topic
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
The Cloudflare Blog
T
Threat Research - Cisco Blogs
A
About on SuperTechFans
H
Help Net Security
MongoDB | Blog
MongoDB | Blog
博客园 - 聂微东
人人都是产品经理
人人都是产品经理
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Latest news
Latest news
G
GRAHAM CLULEY
IT之家
IT之家
C
Cisco Blogs
Last Week in AI
Last Week in AI
Engineering at Meta
Engineering at Meta
L
LangChain Blog
The Register - Security
The Register - Security
SecWiki News
SecWiki News
M
MIT News - Artificial intelligence
NISL@THU
NISL@THU
T
Tenable Blog
博客园 - Franky
美团技术团队
I
Intezer
U
Unit 42
雷峰网
雷峰网
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
S
SegmentFault 最新的问题
C
Cyber Attacks, Cyber Crime and Cyber Security

博客园 - 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;
        }


        
    }


}