如何阅读包含多个工作表的Excel工作表,并仅编辑一个工作表 [英] How to read an Excel sheet with multiple sheets, and edit only a single sheet

查看:93
本文介绍了如何阅读包含多个工作表的Excel工作表,并仅编辑一个工作表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个程序从XML表中获取值并使用TestWriter将它们写入excel表。

I have a program which picks up values from an XML sheet and writes them into an excel sheet, using TestWriter.

FileStream ostrm;
                    StreamWriter strm;
                    TextWriter txtWrt = Console.Out;
                    ostrm = new FileStream(path + "\\Output.xls", FileMode.Truncate, FileAccess.Write);





现在输出文件, Output.xls有多个选项卡,但我只需要截断并写入第一个工作表,而保持其他选项卡不变。我使用下面的代码,但它删除了所有其他标签并编辑了第一个标签



Now the output file, Output.xls has multiple tabs, but I only have to truncate and write into the first sheet, leaving the other tabs untouched. I was using the below code, but it deleted all other tabs and edited the first tab.

public Excel.Application app = null;
        public Excel.Workbook workBook = null;
        public Excel.Worksheet workSheet = null;
        app = new Excel.Application();
                workBook = app.Workbooks.Add();
                workSheet = (Worksheet)workBook.Worksheets.get_Item(1);
                workBook.SaveAs(path+ "\\Output.xls");
                workBook.Close();
                app.Quit();





我需要找到一种可以避免这种情况的方法。



感谢您的期待!



I need to find a way by which this can be avoided.

Thanks in anticipation!

推荐答案

使用 Workbooks.Open [ ^ ]而不是Workbooks.Add [ ^ ];)
Use Workbooks.Open[^] instead Workbooks.Add[^] ;)


这篇关于如何阅读包含多个工作表的Excel工作表,并仅编辑一个工作表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆