返回首页

您好,
& #160; 我创建一个Windows应用程序,当用户进入一个特定的任务,它被存储在一个Excel工作表,在我的文档报告folder.Now我要添加一个功能,使用户可以指定的位置,他要存储的副本从我的文档中的Excel工作表的内容复制到另一个用户定义的Excel工作表location.I我能读懂我的文档的Excel工作表的内容的Excel sheet.iereading,但由word.Can any1 plz帮助的话我写入到另一个Excel工作表的数据吗?
这里是我的阅读我的文档的Excel工作表的Excel工作表的代码。


            Excell.Application xlApp;

            Excell.Workbook xlWorkBook;

            Excell.Worksheet xlWorkSheet;

            Excell.Range range;

 

            string str = "";

            int rCnt = 0;

            int cCnt = 0;

 

            xlApp = new Excell.ApplicationClass();

            object BlankValue = System.Reflection.Missing.Value;

            string docpath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

            string path1 = string.Format(docpath + @"\Report{0:yyyy_MM_dd}.xls",DateTime.Now.Date);

            xlWorkBook = xlApp.Workbooks.Open(path1, 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);

            xlWorkSheet = (Excell.Worksheet)xlWorkBook.Worksheets.get_Item(1);

 

            range = xlWorkSheet.UsedRange;

 

            for (rCnt = 1; rCnt <= range.Rows.Count; rCnt++)

            {

                for (cCnt = 1; cCnt <= range.Columns.Count; cCnt++)

                {

                    str = (string)(range.Cells[rCnt, cCnt] as Excell.Range).Value2;

                    

                }

            }

用这种方法,str是可以只存储在我sheet.How的最后一个字,添加一个List或ArrayList来存储整个数据吗?如何复制到另一个工作表的所有数据......?它使用的StreamWriter ?帮助..

回答

评论会员:koolprasad2003 时间:2012/02/04
阅读Excel单元格由细胞中的ArrayList / DataTable的sttore。和读一遍。这里是很好的链接

]
评论会员:senthilsennu 时间:2012/02/04

           string docpath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

            string path = string.Format(docpath + @"\Report{0:yyyy_MM_dd}.xls",DateTime.Now.Date);

        

string path2 = // User choosen path. Use File Browser to get the path

        try 

        {

            // Create the file and clean up handles.

            using (FileStream fs = File.Create(path)) {}

            // Ensure that the target does not exist.

            File.Delete(path2);

            // Copy the file.

            File.Copy(path, path2);

        } 

        catch 

        {

        

        }

}