c#操作excel的一些记录

//开启Excel APP
            Excel.Application xlApp = new Excel.Application();

//获取程序下bin—>debug下的文件夹的两种方法(System.IO.Directory.GetCurrentDirectory();System.AppDomain.CurrentDomain.BaseDirectory )

//读取模板

sTemplateFilePath = System.IO.Directory.GetCurrentDirectory() + "\ExcelTempFile\直通率.xlsx";

 //开启模板档案
            Excel.Workbook xlBook = xlApp.Workbooks.Open(sTemplateFilePath, Type.Missing, Type.Missing, Type.Missing
                                                , Type.Missing, Type.Missing, Type.Missing, Type.Missing
                                                , Type.Missing, Type.Missing, Type.Missing, Type.Missing
                                                , Type.Missing, Type.Missing, Type.Missing);

 //取得模板的sheets页面用于写入数据
                        Excel.Worksheet RtySheet= (Excel.Worksheet)xlBook.Worksheets["SheetTemp1"];

// Excel.Range oRange1 =RtySheet.get_Range() 用于取得excel中的区域

对excel列是用第一行的字母加第一列的序号来取得位置的;

具体想获取操作的代码可用宏录制;

简单配置xml 并读取数据存入模型

 #region 读取xml中的元素存入list<>;
            List<XMLAutoMailModel> listXML = new List<XMLAutoMailModel>();
            string settingFile = System.AppDomain.CurrentDomain.BaseDirectory + "bin\AutoMailXML.xml";
            XmlDocument doc = new XmlDocument();
            doc.Load(settingFile);
            XmlElement elm = doc.DocumentElement;
            XmlNode node = elm.SelectSingleNode("ProSetting");
            foreach (XmlNode sheet in node.ChildNodes)
            {
                XMLAutoMailModel xmlAutoModel = new XMLAutoMailModel();
                if (sheet.Name == "sheet")
                {

                    xmlAutoModel.Key = sheet.Attributes["Key"].Value;
                    xmlAutoModel.SheetName = sheet.Attributes["SheetName"].Value;
                    xmlAutoModel.ChartTitle = sheet.Attributes["ChartTitle"].Value;
                    foreach (XmlNode condition in sheet.ChildNodes)
                    {
                        xmlAutoModel.ProdType = condition.Attributes["ProdType"].Value;
                        xmlAutoModel.Products = condition.Attributes["Products"].Value;
                    }
                }
                listXML.Add(xmlAutoModel);
            }
            #endregion

原文地址:https://www.cnblogs.com/fighting2014/p/4016308.html