a我考网

 找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 48|回复: 0

[C语言] C#合并多个结构一样的Excel(2)

[复制链接]
发表于 2012-7-31 21:48:08 | 显示全部楼层 |阅读模式
C#合并多个结构一样的Excel(2)* A  P8 b3 K, c/ T! }
public class MergeExcel . O5 i$ h# E+ V& F$ f
  {
7 N  s' Y: O# K* O5 R  Excel.Application app = new Microsoft.Office.Interop.Excel.ApplicationClass();
, }7 h$ r  z, i+ G& S  //保存目标的对象
: Y; V% B7 ~+ R  Excel.Workbook bookDest = null;. _0 R7 w) m) h1 }1 S
  Excel.Worksheet sheetDest = null;
; d4 E* @' k# X. I% u" f  //读取数据的对象
* ]6 b1 {' b) z8 S6 U& N  Excel.Workbook bookSource = null;
' ]& t0 G5 r  c/ f) C. B  Excel.Worksheet sheetSource = null;7 d8 p" K' c, i! r9 a. q3 ]* D; {
  string[] _sourceFiles = null;2 U: }* i* M) B, p
  string _destFile = string.Empty;2 \" w7 U8 |! W* R
  string _columnEnd = string.Empty;
  \% }  J* [7 y$ @  int _headerRowCount = 1;
! J4 i% {: u( K8 O/ ?3 q8 q  int _currentRowCount = 0;, q& r! M) j- X( a2 E8 ?% [
  public MergeExcel(string[] sourceFiles,string destFile,string columnEnd,int headerRowCount)
4 W& X0 c# X! k( m  {  }: Q6 A5 l& U- u  m5 a  X, V
  bookDest = (Excel.WorkbookClass)app.Workbooks.Add(Missing.Value);9 p2 F4 H; |" R) L# `/ v
  sheetDest = bookDest.Worksheets.Add(Missing.Value, Missing.Value, Missing.Value, Missing.Value) as Excel.Worksheet;
# v1 q: k! m  O2 G  sheetDest.Name = "Data";1 s4 E0 B3 ?3 _$ w+ S
  _sourceFiles = sourceFiles;
1 X9 `4 T) A6 R8 N1 v  _destFile = destFile;
; @& @6 p" a1 D/ L; {7 Z  o4 f  _columnEnd = columnEnd;# C# x: s1 L- p3 ~# J
  _headerRowCount = headerRowCount;5 i" r1 a" d. M0 ]/ O& u
  }
, [& q% k: N  ]4 n  ///
6 l+ a& \+ q; K  /// 打开工作表
! b$ p& M. a" W' a) O4 S. e  ///* G; J1 n3 D/ w7 k
  ///
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Woexam.Com ( 湘ICP备18023104号 )

GMT+8, 2024-5-22 15:06 , Processed in 0.244112 second(s), 21 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表