In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
C # operation Excel implementation of the example analysis, I believe that many inexperienced people do not know what to do, so this paper summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.
How does the C # operation Excel perform? What methods will we mainly use in the actual C # operation of Excel development programs? What are the specific implementation steps? Let's introduce it to you in detail through an example:
C # operates Excel instance:
Using System;//C# operation Excel using System.Reflection; namespace CExcel1 {class Class1 {[STAThread] static void Main (string [] args) {/ / create Application object Excel.Application xApp=new Excel.ApplicationClass (); xApp.Visible=true / / you can get the WorkBook object in one of two ways: the following is to open the existing file Excel.Workbook xBook=xApp.Workbooks._Open (@ "D:\ Sample.xls", Missing.Value,Missing.Value,Missing.Value,Missing.Value, Missing.Value,Missing.Value,Missing.Value,Missing.Value, Missing.Value,Missing.Value,Missing.Value,Missing.Value); / / xBook=xApp.Workbooks.Add (Missing.Value) / / Code for creating a new file / / specify the Sheet to be operated in two ways: Excel.Worksheet xSheet= (Excel.Worksheet) xBook.Sheets [1]; / / Excel.Worksheet xSheet= (Excel.Worksheet) xApp.ActiveSheet; / / read data through the Range object Excel.Range rng1=xSheet.get_Range ("A1", Type.Missing); Console.WriteLine (rng1.Value2) / / read, through the Range object, but using different interfaces to get Range Excel.Range rng2= (Excel.Range) xSheet.Cells [3jue 1]; Console.WriteLine (rng2.Value2); / / C# to operate Excel write data Excel.Range rng3=xSheet.get_Range ("C6", Missing.Value); rng3.Value2= "Hello"; rng3.Interior.ColorIndex=6 / / set the background color of Range / / C # Operation Excel save method 1: save WorkBook / / xBook.SaveAs (@ "D:\ CData.xls", Missing.Value,Missing.Value,Missing.Value,Missing.Value, Missing.Value / /, Excel.XlSaveAsAccessMode.xlNoChange, Missing.Value,Missing.Value,Missing.Value / /, Missing.Value,Missing.Value) / / C # operation Excel save method 2: save WorkSheet / / xSheet.SaveAs (@ "D:\ CData2.xls", Missing.Value,Missing.Value,Missing.Value, Missing.Value / /, Missing.Value,Missing.Value,Missing.Value, Missing.Value,Missing.Value); / / C # operation Excel save method 3 xBook.Save (); xSheet=null; xBook=null; xApp.Quit () / / this sentence is very important, otherwise the Excel object cannot exit xApp=null; from memory} read the above content, have you mastered the method of C# operating the instance analysis of Excel implementation? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.