xls到xml
- protected void btn_ok_Click(object sender, EventArgs e)
- {
- string x = txtpath.Text;
- DataSet ds = GetConnect(x);
- DataTable xDataTable = ds.Tables[0];
- string xFile = Server.MapPath("~/") + "action.xml";
- if (File.Exists(xFile))
- File.Delete(xFile);
- //建立Xml的定义声明
- XmlDocument xmlDoc = new XmlDocument();
- try
- {
- XmlDeclaration dec = xmlDoc.CreateXmlDeclaration("1.0", "GB2312", null);
- xmlDoc.AppendChild(dec); //创建根节点
- XmlElement root = xmlDoc.CreateElement("data");
- xmlDoc.AppendChild(root);
- for (int i = 0; i < xDataTable.Rows.Count; i++)
- {
- var str=xDataTable.Rows[i][1].ToString();
- if(str=="")
- {
- break;
- }
- if (i < 5)
- {
- var sdate = "2015年" + (xDataTable.Rows[i][3] + "").Substring(0, 5);
- var edate = "2015年8月" + ((xDataTable.Rows[i][3] + "").Substring(6, 2));
- //TimeSpan days=Convert.ToDateTime(edate) - Convert.ToDateTime(sdate);
- //var n = int.Parse(days.ToString());
- for (int r = 0; r <= 6; r++)
- {
- XmlNode item = xmlDoc.CreateElement("item");
- XmlElement title = xmlDoc.CreateElement("Title");
- title.InnerText = xDataTable.Rows[i][1] + "";
- item.AppendChild(title);
- XmlAttribute xmldate = xmlDoc.CreateAttribute("date");
- xmldate.Value = "8月"+(Convert.ToDateTime(sdate).AddDays(r).ToString()).Substring(7,3)+"日";
- title.Attributes.Append(xmldate);
- XmlAttribute xmlchangguan = xmlDoc.CreateAttribute("changguan");
- xmlchangguan.Value = xDataTable.Rows[i][4] + "";
- title.Attributes.Append(xmlchangguan);
- XmlAttribute xmlisImportion = xmlDoc.CreateAttribute("isImportion");
- xmlisImportion.Value = "1";
- title.Attributes.Append(xmlisImportion);
- XmlElement jiaBin = xmlDoc.CreateElement("jiaBin");
- jiaBin.InnerText = xDataTable.Rows[i][2] + "";
- item.AppendChild(jiaBin);
- XmlElement time = xmlDoc.CreateElement("time");
- time.InnerText = "9:00-21:00";
- item.AppendChild(time);
- XmlElement address = xmlDoc.CreateElement("address");
- address.InnerText = xDataTable.Rows[i][4] + "";
- item.AppendChild(address);
- XmlElement zhuBanDanWei = xmlDoc.CreateElement("zhuBanDanWei");
- zhuBanDanWei.InnerText = xDataTable.Rows[i][5] + "";
- item.AppendChild(zhuBanDanWei);
- root.AppendChild(item);
- }
- }
- else
- {
- XmlNode item = xmlDoc.CreateElement("item");
- XmlElement title = xmlDoc.CreateElement("Title");
- title.InnerText = xDataTable.Rows[i][1] + "";
- item.AppendChild(title);
- XmlAttribute xmldate = xmlDoc.CreateAttribute("date");
- xmldate.Value = (xDataTable.Rows[i][3] + "").Substring(0,5);
- title.Attributes.Append(xmldate);
- XmlAttribute xmlchangguan = xmlDoc.CreateAttribute("changguan");
- xmlchangguan.Value = xDataTable.Rows[i][4] + "";
- title.Attributes.Append(xmlchangguan);
- XmlAttribute xmlisImportion = xmlDoc.CreateAttribute("isImportion");
- xmlisImportion.Value = "1";
- title.Attributes.Append(xmlisImportion);
- XmlElement jiaBin = xmlDoc.CreateElement("jiaBin");
- jiaBin.InnerText = xDataTable.Rows[i][2] + "";
- item.AppendChild(jiaBin);
- XmlElement time = xmlDoc.CreateElement("time");
- int index = (xDataTable.Rows[i][3] + "").IndexOf("日");
- time.InnerText = (xDataTable.Rows[i][3] + "").Substring(index + 1);
- item.AppendChild(time);
- XmlElement address = xmlDoc.CreateElement("address");
- address.InnerText = xDataTable.Rows[i][4] + "";
- item.AppendChild(address);
- XmlElement zhuBanDanWei = xmlDoc.CreateElement("zhuBanDanWei");
- zhuBanDanWei.InnerText = xDataTable.Rows[i][5] + "";
- item.AppendChild(zhuBanDanWei);
- root.AppendChild(item);
- }
- }
- xmlDoc.Save(xFile);
- lblshow.InnerText = "成功";
- }
- catch (Exception ex)
- {
- lblshow.InnerText = "失败" + ex.Message + ex.TargetSite;
- }
- }
- /// <summary>
- /// 导出EXCEL表中的数据到 myDataSet
- /// </summary>
- public static DataSet GetConnect(string FilePath)
- {
- DataSet myDataSet = new DataSet();
- string strCon = "Provider=Microsoft.Jet.Oledb.4.0; Data Source=" + FilePath + "; Extended Properties=\"Excel 8.0; HDR=YES; IMEX=1;\"";
- if (Path.GetExtension(FilePath).ToLower() == ".xlsx")
- strCon = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + FilePath + ";Extended Properties='Excel 12.0;HDR=YES;IMEX=1'";
- OleDbConnection myConn = new OleDbConnection(strCon);
- //条件查询EXCEL表
- string strCom = " SELECT * FROM [Sheet1$] ";
- myConn.Open();
- //打开数据链接,得到一个数据集
- OleDbDataAdapter myCommand = new OleDbDataAdapter(strCom, myConn);
- //创建一个 DataSet对象
- //得到自己的DataSet对象
- myCommand.Fill(myDataSet, "[Sheet1$]");
- //关闭此数据链接
- myConn.Close();
- return myDataSet;
- }
xls到xml的更多相关文章
- xls 和 xml 数据 排序 绑定 -原创
xls 和 xml 排序 xml: <?xml version="1.0" encoding="UTF-8"?> <?xml-styleshe ...
- Report_客制化以PLSQL输出XLS标记实现Excel报表(案例)
2015-02-12 Created By BaoXinjian
- Excel和XML文件导入
using System;using System.Collections;using System.Collections.Generic;using System.Configuration;us ...
- xml与Excel转换
使用Python将如下xml格式转换为Excel格式: xml转为xls格式文件: xml格式如下: <?xml version="1.0" encoding="U ...
- PHP导出XML格式的EXCEL
<?php function Export(){ set_time_limit(0); ob_start(); $biz = new ZaikuBiz(); $biz->setSearch ...
- 【原创】开源BI领袖-SpagoBI5.X最详细的中文版介绍
SpagoBI是唯一100%的开源商业智能套件由 Engineering Group的SpagoBI实验室(www.eng.it)开发和管理.它提供了强大的分析能力,从传统的报表和图表功能到自助分析. ...
- 30 个 PHP 的 Excel 处理类
下面的 PHP Excel 处理类中,包含 Excel 读写.导入导出等相关的类,列表如下: PHP Excel Reader classes 1. Read Excel Spreadsheets u ...
- Python应用与实践【转】
转自:http://www.cnblogs.com/skynet/archive/2013/05/06/3063245.html 目录 1. Python是什么? 1.1. Pyt ...
- 29 个 PHP 的 Excel 处理类
下面的 PHP Excel 处理类中,包含 Excel 读写.导入导出等相关的类,列表如下: PHP Excel Reader classes 1. Read Excel Spreadsheets u ...
随机推荐
- 如何增加Ubuntu交换空间swap
如何增加Ubuntu交换空间swap 1 使用命令查看系统内swap分区大小 green@green:~$ free -m total used free shared buff/cache ava ...
- 接口自动化框架(java)--1.项目概述
项目github地址: https://github.com/tianchiTester/API_AutoFramework 这套框架的报告是自己封装的 1.测试基类TestBase: 接口请求的te ...
- kali,parrot最新更新debain源
deb http://mirrors.163.com/debian/ jessie main non-free contribdeb http://mirrors.163.com/debian/ je ...
- 关于Linux与Windows的在服务器的一些区别
我们平时说学习运维要依托于Linux系统,因为在服务器领域Linux基本取得了市场,那么Linux在服务器领域与Windows相比有哪些优势呢?我们来看下:我们选择服务器主要是成本,安全稳定,这两大方 ...
- PHP----------linux下安装opcache.
1.首先查看是否安装了opcache扩展,使用php -m 命令查看安装的扩展(没有添加环境变量就使用:/usr/local/php/bin/php -m). 添加opcache扩展.(我自己封装的s ...
- flask hook
@app.before_first_requestdef before_first_request(): """在第一次请求之前会访问该函数""&qu ...
- Servlet基本知识总结
Servlet 简介 Servlet是什么? Servlet是一个Java编写的程序,此程序是基于Http协议的,并运行在web服务器上或者应用服务器上.它主要是作为web浏览器或其他Http客户端的 ...
- Catch That Cow (BFS广搜)
问题描述: Farmer John has been informed of the location of a fugitive cow and wants to catch her immedia ...
- 洛谷P2611 信息传递
并查集裸题,记录每个点的胜读,取个min就好了 #include<stdio.h> #include<string.h> #include<algorithm> u ...
- 论文速读(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-- ...