1.   protected void btn_ok_Click(object sender, EventArgs e)
  2.     {
  3.         string x = txtpath.Text;
  4.         DataSet ds = GetConnect(x);
  5.         DataTable xDataTable = ds.Tables[0];
  6.  
  7.         string xFile = Server.MapPath("~/") + "action.xml";
  8.         if (File.Exists(xFile))
  9.             File.Delete(xFile);
  10.         //建立Xml的定义声明  
  11.         XmlDocument xmlDoc = new XmlDocument();
  12.         try
  13.         {
  14.  
  15.             XmlDeclaration dec = xmlDoc.CreateXmlDeclaration("1.0", "GB2312", null);
  16.  
  17.             xmlDoc.AppendChild(dec);   //创建根节点   
  18.             XmlElement root = xmlDoc.CreateElement("data");
  19.             xmlDoc.AppendChild(root);
  20.             for (int i = 0; i < xDataTable.Rows.Count; i++)
  21.             {
  22.                 var str=xDataTable.Rows[i][1].ToString();
  23.                 if(str=="")
  24.                 {
  25.                     break;
  26.                 }
  27.  
  28.                 if (< 5)
  29.                 {
  30.                     var sdate = "2015年" + (xDataTable.Rows[i][3] + "").Substring(0, 5);
  31.                     var edate = "2015年8月" + ((xDataTable.Rows[i][3] + "").Substring(6, 2));
  32.                     //TimeSpan days=Convert.ToDateTime(edate) - Convert.ToDateTime(sdate);
  33.                     //var n = int.Parse(days.ToString());
  34.                     for (int r = 0; r <= 6; r++)
  35.                     {
  36.  
  37.                         XmlNode item = xmlDoc.CreateElement("item");
  38.                         XmlElement title = xmlDoc.CreateElement("Title");
  39.                         title.InnerText = xDataTable.Rows[i][1] + "";
  40.                         item.AppendChild(title);
  41.                         XmlAttribute xmldate = xmlDoc.CreateAttribute("date");
  42.                         xmldate.Value = "8月"+(Convert.ToDateTime(sdate).AddDays(r).ToString()).Substring(7,3)+"日";
  43.                         title.Attributes.Append(xmldate);
  44.                         XmlAttribute xmlchangguan = xmlDoc.CreateAttribute("changguan");
  45.                         xmlchangguan.Value = xDataTable.Rows[i][4] + "";
  46.                         title.Attributes.Append(xmlchangguan);
  47.                         XmlAttribute xmlisImportion = xmlDoc.CreateAttribute("isImportion");
  48.                         xmlisImportion.Value = "1";
  49.                         title.Attributes.Append(xmlisImportion);
  50.  
  51.                         XmlElement jiaBin = xmlDoc.CreateElement("jiaBin");
  52.                         jiaBin.InnerText = xDataTable.Rows[i][2] + "";
  53.                         item.AppendChild(jiaBin);
  54.  
  55.                         XmlElement time = xmlDoc.CreateElement("time");
  56.                         time.InnerText = "9:00-21:00";
  57.                         item.AppendChild(time);
  58.  
  59.                         XmlElement address = xmlDoc.CreateElement("address");
  60.                         address.InnerText = xDataTable.Rows[i][4] + "";
  61.                         item.AppendChild(address);
  62.  
  63.                         XmlElement zhuBanDanWei = xmlDoc.CreateElement("zhuBanDanWei");
  64.                         zhuBanDanWei.InnerText = xDataTable.Rows[i][5] + "";
  65.                         item.AppendChild(zhuBanDanWei);
  66.  
  67.                         root.AppendChild(item);
  68.                     }
  69.                 }
  70.                 else
  71.                 {
  72.                     XmlNode item = xmlDoc.CreateElement("item");
  73.                     XmlElement title = xmlDoc.CreateElement("Title");
  74.                     title.InnerText = xDataTable.Rows[i][1] + "";
  75.                     item.AppendChild(title);
  76.                     XmlAttribute xmldate = xmlDoc.CreateAttribute("date");
  77.                     xmldate.Value = (xDataTable.Rows[i][3] + "").Substring(0,5);
  78.                     title.Attributes.Append(xmldate);
  79.                     XmlAttribute xmlchangguan = xmlDoc.CreateAttribute("changguan");
  80.                     xmlchangguan.Value = xDataTable.Rows[i][4] + "";
  81.                     title.Attributes.Append(xmlchangguan);
  82.                     XmlAttribute xmlisImportion = xmlDoc.CreateAttribute("isImportion");
  83.                     xmlisImportion.Value = "1";
  84.                     title.Attributes.Append(xmlisImportion);
  85.  
  86.                     XmlElement jiaBin = xmlDoc.CreateElement("jiaBin");
  87.                     jiaBin.InnerText = xDataTable.Rows[i][2] + "";
  88.                     item.AppendChild(jiaBin);
  89.  
  90.                     XmlElement time = xmlDoc.CreateElement("time");
  91.                     int index = (xDataTable.Rows[i][3] + "").IndexOf("日");
  92.                     time.InnerText = (xDataTable.Rows[i][3] + "").Substring(index + 1);
  93.                     item.AppendChild(time);
  94.  
  95.                     XmlElement address = xmlDoc.CreateElement("address");
  96.                     address.InnerText = xDataTable.Rows[i][4] + "";
  97.                     item.AppendChild(address);
  98.  
  99.                     XmlElement zhuBanDanWei = xmlDoc.CreateElement("zhuBanDanWei");
  100.                     zhuBanDanWei.InnerText = xDataTable.Rows[i][5] + "";
  101.                     item.AppendChild(zhuBanDanWei);
  102.  
  103.                     root.AppendChild(item);
  104.                 }
  105.             }
  106.  
  107.             xmlDoc.Save(xFile);
  108.             lblshow.InnerText = "成功";
  109.         }
  110.         catch (Exception ex)
  111.         {
  112.             lblshow.InnerText = "失败" + ex.Message + ex.TargetSite;
  113.         }
  114.  
  115.     }
  116.     /// <summary>
  117.     /// 导出EXCEL表中的数据到 myDataSet
  118.     /// </summary>
  119.     public static DataSet GetConnect(string FilePath)
  120.     {
  121.         DataSet myDataSet = new DataSet();
  122.         string strCon = "Provider=Microsoft.Jet.Oledb.4.0; Data Source=" + FilePath + "; Extended Properties=\"Excel 8.0; HDR=YES; IMEX=1;\"";
  123.         if (Path.GetExtension(FilePath).ToLower() == ".xlsx")
  124.             strCon = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + FilePath + ";Extended Properties='Excel 12.0;HDR=YES;IMEX=1'";
  125.         OleDbConnection myConn = new OleDbConnection(strCon);
  126.         //条件查询EXCEL表
  127.         string strCom = " SELECT * FROM [Sheet1$] ";
  128.         myConn.Open();
  129.         //打开数据链接,得到一个数据集
  130.         OleDbDataAdapter myCommand = new OleDbDataAdapter(strCom, myConn);
  131.         //创建一个 DataSet对象
  132.  
  133.         //得到自己的DataSet对象
  134.         myCommand.Fill(myDataSet, "[Sheet1$]");
  135.         //关闭此数据链接
  136.         myConn.Close();
  137.         return myDataSet;
  138.     }

xls到xml的更多相关文章

  1. xls 和 xml 数据 排序 绑定 -原创

    xls 和 xml 排序 xml: <?xml version="1.0" encoding="UTF-8"?> <?xml-styleshe ...

  2. Report_客制化以PLSQL输出XLS标记实现Excel报表(案例)

    2015-02-12 Created By BaoXinjian

  3. Excel和XML文件导入

    using System;using System.Collections;using System.Collections.Generic;using System.Configuration;us ...

  4. xml与Excel转换

    使用Python将如下xml格式转换为Excel格式: xml转为xls格式文件: xml格式如下: <?xml version="1.0" encoding="U ...

  5. PHP导出XML格式的EXCEL

    <?php function Export(){ set_time_limit(0); ob_start(); $biz = new ZaikuBiz(); $biz->setSearch ...

  6. 【原创】开源BI领袖-SpagoBI5.X最详细的中文版介绍

    SpagoBI是唯一100%的开源商业智能套件由 Engineering Group的SpagoBI实验室(www.eng.it)开发和管理.它提供了强大的分析能力,从传统的报表和图表功能到自助分析. ...

  7. 30 个 PHP 的 Excel 处理类

    下面的 PHP Excel 处理类中,包含 Excel 读写.导入导出等相关的类,列表如下: PHP Excel Reader classes 1. Read Excel Spreadsheets u ...

  8. Python应用与实践【转】

    转自:http://www.cnblogs.com/skynet/archive/2013/05/06/3063245.html 目录 1.      Python是什么? 1.1.      Pyt ...

  9. 29 个 PHP 的 Excel 处理类

    下面的 PHP Excel 处理类中,包含 Excel 读写.导入导出等相关的类,列表如下: PHP Excel Reader classes 1. Read Excel Spreadsheets u ...

随机推荐

  1. 如何增加Ubuntu交换空间swap

    如何增加Ubuntu交换空间swap 1  使用命令查看系统内swap分区大小 green@green:~$ free -m total used free shared buff/cache ava ...

  2. 接口自动化框架(java)--1.项目概述

    项目github地址: https://github.com/tianchiTester/API_AutoFramework 这套框架的报告是自己封装的 1.测试基类TestBase: 接口请求的te ...

  3. kali,parrot最新更新debain源

    deb http://mirrors.163.com/debian/ jessie main non-free contribdeb http://mirrors.163.com/debian/ je ...

  4. 关于Linux与Windows的在服务器的一些区别

    我们平时说学习运维要依托于Linux系统,因为在服务器领域Linux基本取得了市场,那么Linux在服务器领域与Windows相比有哪些优势呢?我们来看下:我们选择服务器主要是成本,安全稳定,这两大方 ...

  5. PHP----------linux下安装opcache.

    1.首先查看是否安装了opcache扩展,使用php -m 命令查看安装的扩展(没有添加环境变量就使用:/usr/local/php/bin/php -m). 添加opcache扩展.(我自己封装的s ...

  6. flask hook

    @app.before_first_requestdef before_first_request(): """在第一次请求之前会访问该函数""&qu ...

  7. Servlet基本知识总结

    Servlet 简介 Servlet是什么? Servlet是一个Java编写的程序,此程序是基于Http协议的,并运行在web服务器上或者应用服务器上.它主要是作为web浏览器或其他Http客户端的 ...

  8. Catch That Cow (BFS广搜)

    问题描述: Farmer John has been informed of the location of a fugitive cow and wants to catch her immedia ...

  9. 洛谷P2611 信息传递

    并查集裸题,记录每个点的胜读,取个min就好了 #include<stdio.h> #include<string.h> #include<algorithm> u ...

  10. 论文速读(Jiaming Liu——【2019】Detecting Text in the Wild with Deep Character Embedding Network )

    Jiaming Liu--[2019]Detecting Text in the Wild with Deep Character Embedding Network 论文 Jiaming Liu-- ...