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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值