zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    idea存在包但是运行项目一直报java.lang.NoClassDefFoundError的问题
    记录一次服务器大中间表优化的问题(数据倾斜的解决)
    CDH spark2切换成anaconda3的问题
    关于(我们流量表优化),分区表数据块过多,聚合又导致数据倾斜问题
    大数据(流量表)任务问题清洗生成新分区表过程
    spark2.0在IDE运行的问题
    位运算应用
    SPSS数据的图表
    SPSS数据输入
    箭头函数中的this
  • 原文地址:https://www.cnblogs.com/fighting2014/p/4016308.html
Copyright © 2011-2022 走看看