Пример #1
0
        //xml转换成excel事件
        private void btnXMLToExcel_Click(object sender, EventArgs e)
        {
            String xmlFilePath = this.XMLPath.Text;   //xml文件夹路径
            String printPath   = this.printPath.Text; //生成文件的路径    这里为excel文件的路径

            if (!Directory.Exists(xmlFilePath))       //xml的路径不存在 直接结束
            {
                DialogResult dr = MessageBox.Show("文件夹内未有xml文件");
                return;
            }
            if (!Directory.Exists(printPath))//不存在,使用xml的路径
            {
                printPath = xmlFilePath;
            }
            String        guid   = System.Guid.NewGuid().ToString();//生成的guid
            DirectoryInfo folder = new DirectoryInfo(xmlFilePath);

            XMLOperate   xmlOperate   = new XMLOperate();
            ExcelOperate excelOperate = new ExcelOperate();

            List <XMLObject> xmlObjectList = new List <XMLObject>();

            foreach (FileInfo file in folder.GetFiles("*.xml"))
            {
                xmlObjectList.Add(xmlOperate.XMLFiletoObject(xmlFilePath, file.Name));//一个xml文件内的数据转成object
            }
            excelOperate.XMLObjectAddToExcel(xmlObjectList, xmlFilePath);
            MessageBox.Show("xml文件已经转成excel文件", "确定");
        }
Пример #2
0
        //excel转换成xml事件
        private void btnExcelToXML_Click(object sender, EventArgs e)
        {
            String excelDataPath = this.excelPath.Text; //excel文件的路径
            String printPath     = this.printPath.Text; //生成文件的路径

            if (!Directory.Exists(printPath))           //生产xml的路径不存在 直接结束
            {
                printPath = excelDataPath.Substring(0, excelDataPath.LastIndexOf("\\"));
            }
            XMLOperate       xmlOperate    = new XMLOperate();
            ExcelOperate     excelOperate  = new ExcelOperate();
            List <XMLObject> xmlObjectList = excelOperate.ExcelToXMLObject(excelDataPath);

            foreach (XMLObject xmlObject in xmlObjectList)
            {
                xmlOperate.ObjectToXMLFile(printPath, xmlObject);
            }
            MessageBox.Show("excel已经转成xml文件", "确定");
        }