| 订阅 | 在线投稿
分享
 
 
当前位置: 王朝网络 >> c# >> C# he bing duo ge jie gou yi yang de Excel

C# he bing duo ge jie gou yi yang de Excel

2008-08-20 08:08:40 编辑來源:互联网 评论
 
 
 
本文为【C#合并多个结构一样的Excel】的拼音翻译版
  he bing dai ma ru xia :
  using System;
  using System.Collections.Generic;
  using System.Text;
  using System.Reflection;
  using Excel = Microsoft.Office.Interop.Excel;
  namespace ConsoleApplication20
  {
   // tian jia yin yong -COM-MicroSoft Excel 11.0 Object Libery
   class Program
   {
   static void Main(string[] args)
   {
   //M wei biao ge kuan du biao zhi (Excel zhong de di M lie wei zui hou yi lie ),3 wei biao tou gao du
   MergeExcel.DoMerge(new string[]
   {
   @"E:\excel\ lei xing A\ gong si A.xls",
   @"E:\excel\ lei xing A\ gong si B.xls"
   },
   @"E:\excel\ lei xing A\ he bing ce shi .xls", "M", 3);
   MergeExcel.DoMerge(new string[]
   {
   @"E:\excel\ lei xing B\ tong ji biao A.xls",
   @"E:\excel\ lei xing B\ tong ji biao B.xls"
   },
   @"E:\excel\ lei xing B\ he bing ce shi .xls", "I", 4);
   }
  
   }
   public class MergeExcel
   {
  
   Excel.Application app = new Microsoft.Office.Interop.Excel.ApplicationClass();
   // bao cun mu biao de dui xiang
   Excel.Workbook bookDest = null;
   Excel.Worksheet sheetDest = null;
   // du qu shu ju de dui xiang
   Excel.Workbook bookSource = null;
   Excel.Worksheet sheetSource = null;
   string[] _sourceFiles = null;
   string _destFile = string.Empty;
   string _columnEnd = string.Empty;
   int _headerRowCount = 1;
   int _currentRowCount = 0;
   public MergeExcel(string[] sourceFiles,string destFile,string columnEnd,int headerRowCount)
   {
  
   bookDest = (Excel.WorkbookClass)app.Workbooks.Add(Missing.Value);
   sheetDest = bookDest.Worksheets.Add(Missing.Value, Missing.Value, Missing.Value, Missing.Value) as Excel.Worksheet;
   sheetDest.Name = "Data";
   _sourceFiles = sourceFiles;
   _destFile = destFile;
   _columnEnd = columnEnd;
   _headerRowCount = headerRowCount;
   }
   /// <summary>
   /// da kai gong zuo biao
   /// </summary>
   /// <param name="fileName"></param>
   void OpenBook(string fileName)
   {
   bookSource = app.Workbooks._Open(fileName, Missing.Value, Missing.Value, Missing.Value, Missing.Value
   , Missing.Value, Missing.Value, Missing.Value, Missing.Value
   , Missing.Value, Missing.Value, Missing.Value, Missing.Value);
   sheetSource = bookSource.Worksheets[1] as Excel.Worksheet;
   }
   /// <summary>
   /// guan bi gong zuo biao
   /// </summary>
   void CloseBook()
   {
   bookSource.Close(false, Missing.Value, Missing.Value);
   }
   /// <summary>
   /// fu zhi biao tou
   /// </summary>
   void CopyHeader()
   {
   Excel.Range range = sheetSource.get_Range("A1", _columnEnd + _headerRowCount.ToString());
   range.Copy(sheetDest.get_Range("A1",Missing.Value));
   _currentRowCount += _headerRowCount;
   }
   /// <summary>
   /// fu zhi shu ju
   /// </summary>
   void CopyData()
   {
   int sheetRowCount = sheetSource.UsedRange.Rows.Count;
   Excel.Range range = sheetSource.get_Range(string.Format("A{0}", _headerRowCount + 1), _columnEnd + sheetRowCount.ToString());
   range.Copy(sheetDest.get_Range(string.Format("A{0}", _currentRowCount + 1), Missing.Value));
   _currentRowCount += range.Rows.Count;
   }
   /// <summary>
   /// bao cun jie guo
   /// </summary>
   void Save()
   {
   bookDest.Saved = true;
   bookDest.SaveCopyAs(_destFile);
   }
   /// <summary>
   /// tui chu jin cheng
   /// </summary>
   void Quit()
   {
   app.Quit();
   }
   /// <summary>
   /// he bing
   /// </summary>
   void DoMerge()
   {
   bool b = false;
   foreach (string strFile in _sourceFiles)
   {
   OpenBook(strFile);
   if (b == false)
   {
   CopyHeader();
   b = true;
   }
   CopyData();
   CloseBook();
   }
   Save();
   Quit();
   }
   /// <summary>
   /// he bing biao ge
   /// </summary>
   /// <param name="sourceFiles"> yuan wen jian </param>
   /// <param name="destFile"> mu biao wen jian </param>
   /// <param name="columnEnd"> zui hou yi lie biao zhi </param>
   /// <param name="headerRowCount"> biao tou xing shu </param>
   public static void DoMerge(string[] sourceFiles, string destFile, string columnEnd, int headerRowCount)
   {
   new MergeExcel(sourceFiles, destFile, columnEnd, headerRowCount).DoMerge();
   }
   }
  }【原文】【汉音对照
 
 
 
 
 
 
 
 
 
日版宠物情人插曲《Winding Road》歌词

日版宠物情人2017的插曲,很带节奏感,日语的,女生唱的。 最后听见是在第8集的时候女主手割伤了,然后男主用嘴帮她吸了一下,插曲就出来了。 歌手:Def...

兄弟共妻,我成了他们夜里的美食

老钟家的两个儿子很特别,就是跟其他的人不太一样,魔一般的执着。兄弟俩都到了要结婚的年龄了,不管自家老爹怎么磨破嘴皮子,兄弟俩说不娶就不娶,老父母为兄弟两操碎了心...

如何磨出破洞牛仔裤?牛仔裤怎么剪破洞?

把牛仔裤磨出有线的破洞 1、具体工具就是磨脚石,下面垫一个硬物,然后用磨脚石一直磨一直磨,到把那块磨薄了,用手撕开就好了。出来的洞啊很自然的。需要猫须的话调几...

我就是扫描下图得到了敬业福和爱国福

先来看下敬业福和爱国福 今年春节,支付宝再次推出了“五福红包”活动,表示要“把欠大家的敬业福都还给大家”。 今天该活动正式启动,和去年一样,需要收集“五福”...

冰箱异味产生的原因和臭味去除的方法

有时候我们打开冰箱就会闻到一股异味,冰箱里的这种异味是因为一些物质发出的气味的混合体,闻起来让人恶心。 产生这些异味的主要原因有以下几点。 1、很多人有这种习...

 
 
he bing dai ma ru xia : using System; using System.Collections.Generic; using System.Text; using System.Reflection; using Excel = Microsoft.Office.Interop.Excel; namespace ConsoleApplication20 { // tian jia yin yong -COM-MicroSoft Excel 11.0 Object Libery class Program { static void Main(string[] args) { //M wei biao ge kuan du biao zhi (Excel zhong de di M lie wei zui hou yi lie ),3 wei biao tou gao du MergeExcel.DoMerge(new string[] { @"E:\excel\ lei xing A\ gong si A.xls", @"E:\excel\ lei xing A\ gong si B.xls" }, @"E:\excel\ lei xing A\ he bing ce shi .xls", "M", 3); MergeExcel.DoMerge(new string[] { @"E:\excel\ lei xing B\ tong ji biao A.xls", @"E:\excel\ lei xing B\ tong ji biao B.xls" }, @"E:\excel\ lei xing B\ he bing ce shi .xls", "I", 4); } } public class MergeExcel { Excel.Application app = new Microsoft.Office.Interop.Excel.ApplicationClass(); // bao cun mu biao de dui xiang Excel.Workbook bookDest = null; Excel.Worksheet sheetDest = null; // du qu shu ju de dui xiang Excel.Workbook bookSource = null; Excel.Worksheet sheetSource = null; string[] _sourceFiles = null; string _destFile = string.Empty; string _columnEnd = string.Empty; int _headerRowCount = 1; int _currentRowCount = 0; public MergeExcel(string[] sourceFiles,string destFile,string columnEnd,int headerRowCount) { bookDest = (Excel.WorkbookClass)app.Workbooks.Add(Missing.Value); sheetDest = bookDest.Worksheets.Add(Missing.Value, Missing.Value, Missing.Value, Missing.Value) as Excel.Worksheet; sheetDest.Name = "Data"; _sourceFiles = sourceFiles; _destFile = destFile; _columnEnd = columnEnd; _headerRowCount = headerRowCount; } /// <summary> /// da kai gong zuo biao /// </summary> /// <param name="fileName"></param> void OpenBook(string fileName) { bookSource = app.Workbooks._Open(fileName, Missing.Value, Missing.Value, Missing.Value, Missing.Value , Missing.Value, Missing.Value, Missing.Value, Missing.Value , Missing.Value, Missing.Value, Missing.Value, Missing.Value); sheetSource = bookSource.Worksheets[1] as Excel.Worksheet; } /// <summary> /// guan bi gong zuo biao /// </summary> void CloseBook() { bookSource.Close(false, Missing.Value, Missing.Value); } /// <summary> /// fu zhi biao tou /// </summary> void CopyHeader() { Excel.Range range = sheetSource.get_Range("A1", _columnEnd + _headerRowCount.ToString()); range.Copy(sheetDest.get_Range("A1",Missing.Value)); _currentRowCount += _headerRowCount; } /// <summary> /// fu zhi shu ju /// </summary> void CopyData() { int sheetRowCount = sheetSource.UsedRange.Rows.Count; Excel.Range range = sheetSource.get_Range(string.Format("A{0}", _headerRowCount + 1), _columnEnd + sheetRowCount.ToString()); range.Copy(sheetDest.get_Range(string.Format("A{0}", _currentRowCount + 1), Missing.Value)); _currentRowCount += range.Rows.Count; } /// <summary> /// bao cun jie guo /// </summary> void Save() { bookDest.Saved = true; bookDest.SaveCopyAs(_destFile); } /// <summary> /// tui chu jin cheng /// </summary> void Quit() { app.Quit(); } /// <summary> /// he bing /// </summary> void DoMerge() { bool b = false; foreach (string strFile in _sourceFiles) { OpenBook(strFile); if (b == false) { CopyHeader(); b = true; } CopyData(); CloseBook(); } Save(); Quit(); } /// <summary> /// he bing biao ge /// </summary> /// <param name="sourceFiles"> yuan wen jian </param> /// <param name="destFile"> mu biao wen jian </param> /// <param name="columnEnd"> zui hou yi lie biao zhi </param> /// <param name="headerRowCount"> biao tou xing shu </param> public static void DoMerge(string[] sourceFiles, string destFile, string columnEnd, int headerRowCount) { new MergeExcel(sourceFiles, destFile, columnEnd, headerRowCount).DoMerge(); } } }
󰈣󰈤
  免责声明:本文仅代表作者个人观点,与王朝网络无关。王朝网络登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述,其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
情人节的清纯女生(9)
情人节的清纯女生(8)
情人节的清纯女生(7)
情人节的清纯女生(6)
山东蓬莱海边组照
一探哲蚌 II
一探哲蚌 III
古长城的一角
 
>>返回首页<<
 
 
 为你推荐
 
 
 
 转载本文
 UBB代码 HTML代码
复制到剪贴板...
 
 热帖排行
 
 
 
 
 
©2005- 王朝网络 版权所有