整合營銷服務(wù)商

          電腦端+手機(jī)端+微信端=數(shù)據(jù)同步管理

          免費(fèi)咨詢熱線:

          CSV to SQLConverter方便的數(shù)據(jù)格式

          CSV to SQLConverter方便的數(shù)據(jù)格式轉(zhuǎn)換工具

          SV to SQL Converter是一款文件格式轉(zhuǎn)換工具,用戶能夠使用這款軟件方便的將CSV格式的文件轉(zhuǎn)換為SQL文件進(jìn)行保存。軟件使用方式簡單,具有簡單的使用界面,并且支持輸出為UTF-8或者ANSI兩種不同的編碼格式,并且能夠自定義文件的保存名稱。

          轉(zhuǎn)載自當(dāng)游網(wǎng),原文地址:http://www.3h3.com/soft/218449.html

          、前言

          在日常運(yùn)維的過程中,執(zhí)行腳本,生成excel報表并發(fā)送郵件到郵箱是不可避免的,python生成excel的庫有很多,這里選擇生成csv格式,因?yàn)閜ython內(nèi)置,不需要額外安裝模塊,而且使用簡單。

          二、生產(chǎn)CSV代碼

          # encoding: utf-8
          import codecs
          import csv
          import datetime
          
          import sys
          reload(sys)
          sys.setdefaultencoding( "utf-8" )
          def to_csv(datas, env):
              headers=['ip', u'操作系統(tǒng)', u'分區(qū)屬性', u'輸出返回', u'執(zhí)行結(jié)果']
              # newline=''避免出現(xiàn)空行
              today=datetime.date.today()
              filename="{}-{}.csv".format(env, today)
              try:
                  with open(filename, 'wb') as f:
                      f.write(codecs.BOM_UTF8)
                      # 標(biāo)頭在這里傳入,作為第一行數(shù)據(jù)
                      writer=csv.DictWriter(f, headers)
                      writer.writeheader()
                      writer.writerows(datas)
              except Exception as e:
                  print (u'寫入csv錯誤:' + str(e))
              finally:
                  return filename
          
          
          if __name__=='__main__':
              data=[{"ip": "192.168.1.2", u'操作系統(tǒng)': "LINUX", u'分區(qū)屬性': u"x86物理機(jī)", u'輸出返回': "ok", u'執(zhí)行結(jié)果': u"成功"},
                      {"ip": "192.168.1.3", u'操作系統(tǒng)': "LINUX", u'分區(qū)屬性': u"x86物理機(jī)", u'輸出返回': "error:xxxxxxxxxxx", u'執(zhí)行結(jié)果': u"成功"},
                      {"ip": "192.168.1.4", u'操作系統(tǒng)': "LINUX", u'分區(qū)屬性': u"x86虛擬機(jī)", u'輸出返回': "ok", u'執(zhí)行結(jié)果': u"成功"},
                      {"ip": "192.168.1.5", u'操作系統(tǒng)': "LINUX", u'分區(qū)屬性': u"x86虛擬機(jī)", u'輸出返回': "ok", u'執(zhí)行結(jié)果': u"成功"}]
              env="dev"
              to_csv(data, env)

          生成的文件:

          二、發(fā)送郵件代碼

          oi框架 framework-poi

          > 簡單、好用且輕量級的海量excel,csv文件導(dǎo)入導(dǎo)出解決方案。解決火狐瀏覽器中文編碼問題。

          > 注:excel的合并功能及復(fù)雜功能,使用代碼實(shí)現(xiàn)比較復(fù)雜,框架只提供單行的導(dǎo)入導(dǎo)出。

          如何使用?

          引入Maven依賴或下載jar包

           <dependency>
           <groupId>com.github.fartherp</groupId>
           <artifactId>framework-poi</artifactId>
           <version>3.0.4</version>
           </dependency>
          

          CSV常用例子:

           CSVRead.read(CSVReadTest.class.getResourceAsStream("/a.csv"), new CSVReadDeal<CsvReadDto>() { 
           // 單條數(shù)據(jù)處理(每一行對應(yīng)一個javabean)
           public CsvReadDto dealBean(String[] arr) {
           CsvReadDto dto=new CsvReadDto();
           dto.setId(Long.valueOf(arr[0]));
           dto.setName(arr[1]);
           dto.setAge(Integer.valueOf(arr[2])); 
           return dto;
           } 
           // 批量數(shù)據(jù)處理(可以批量入庫)
           public void dealBatchBean(List<CsvReadDto> list) {
           Assert.assertEquals("name1";, list.get(0).getName());
           Assert.assertEquals("name2", list.get(1).getName());
           Assert.assertEquals("name3", list.get(2).getName());
           } 
           // 批量加載多少數(shù)據(jù),統(tǒng)一處理(默認(rèn)1000)
           public int getBatchCount() { 
           return super.getBatchCount();
           } 
           // 從第幾行開始加載(默認(rèn)跳過第一行)
           public int skipLine() { 
           return super.skipLine();
           }
           });
          

          2.CSV文件導(dǎo)出:

           String filename="TEST";
           String[] title=SheetsTitlesEnum.USER_LOGIN_LOG.getTitle();
           List<String[]> bodyList=new ArrayList<>();
           CsvUtil.writeCsvFile(filename, title, bodyList);
          

          3.瀏覽器下載CSV文件:

           HttpServletResponse response=null;
           HttpServletRequest request=null;
           String filename="TEST";
           String[] title=SheetsTitlesEnum.USER_LOGIN_LOG.getTitle();
           List<String[]> bodyList=new ArrayList<>();
           CsvUtil.writeCsvFile(response, request, filename, title, bodyList);
          

          Excel常用例子:

          1.Excel文件導(dǎo)入:

           ExcelRead.read(ExcelReadTest.class.getResourceAsStream("/a.xls"), new ExcelReadDeal<ExcelReadDto>() { 
           // 單條數(shù)據(jù)處理(每一行對應(yīng)一個javabean)
           public ExcelReadDto dealBean(Row row) {
           ExcelReadDto dto=new ExcelReadDto();
           dto.setId(new BigDecimal(row.getCell(0).toString()).longValue());
           dto.setName(row.getCell(1).toString());
           dto.setAge(Integer.valueOf(row.getCell(2).toString())); 
           return dto;
           } 
           // 批量數(shù)據(jù)處理(可以批量入庫)
           public void dealBatchBean(List<ExcelReadDto> list) {
           Assert.assertEquals("name1", list.get(0).getName());
           Assert.assertEquals("name2", list.get(1).getName());
           Assert.assertEquals("name3", list.get(2).getName());
           } 
           // 批量加載多少數(shù)據(jù),統(tǒng)一處理(默認(rèn)1000)
           public int getBatchCount() { 
           return super.getBatchCount();
           } 
           // 從第幾行開始加載(默認(rèn)跳過第一行)
           public int skipLine() { 
           return super.skipLine();
           }
           });
          

          2.Excel文件導(dǎo)出:

           String[] title=new String [6];
           title[0]="登錄時間";
           title[1]="用戶名";
           title[2]="訪問端";
           title[3]="版本系統(tǒng)";
           title[4]="登錄IP";
           title[5]="狀態(tài)";
           String fileName="D:\\style1.xls";
           FileExcelWrite.<ExcelDto>build(title, fileName)
           .setLargeDataMode(false)
           .deal(obj -> {
           String[] result=new String[6];
           result[0]=obj.getTime();
           result[1]=obj.getName();
           result[2]=obj.getClient();
           result[3]=obj.getVersion();
           result[4]=obj.getIp();
           result[5]=obj.getStatus() + ""; 
           return result;
           })
           .list(ExcelWriteStyleTest.getList())// 默認(rèn)情況下導(dǎo)出數(shù)據(jù)達(dá)到excel最大行,自動切換sheet,(xlsx=1048576,xls=65536)
           .list(ExcelWriteStyleTest.getList1())
           .write();
          

          3.Excel文件導(dǎo)出(風(fēng)格,可以自定義風(fēng)格):

           Map<String, Object> map=new HashMap<>();
           map.put("quoteCurrency", "ETH");
           map.put("symbol", "USDT_ETH");
           map.put("startTime", "2019-01-09 00:00:00");
           map.put("endTime", "2019-01-09 12:00:00");
           String fileName="D:\\styleInputStream.xls";
           FileExcelWrite.<ExcelDto>build(this.getClass().getResourceAsStream("/c.xls"), fileName)
           .additional(map)
           .deal(new WriteDeal<ExcelDto>() { 
           public String[] dealBean(ExcelDto obj) {
           String[] result=new String[3];
           result[0]=obj.getId() + "";
           result[1]=obj.getName();
           result[2]=obj.getAge() + ""; 
           return result;
           } 
           public int skipLine() { 
           return 4;
           }
           })
           .list(getList())
           .write();
          

          4.瀏覽器下載Excel文件:

           String[] title=new String [6];
           title[0]="登錄時間";
           title[1]="用戶名";
           title[2]="訪問端";
           title[3]="版本系統(tǒng)";
           title[4]="登錄IP";
           title[5]="狀態(tài)";
           String fileName="D:\\style1.xls";
           HttpServletResponseExcelWrite.<ExcelDto>build(title, fileName, request, response)
           .setLargeDataMode(false)
           .deal(obj -> {
           String[] result=new String[6];
           result[0]=obj.getTime();
           result[1]=obj.getName();
           result[2]=obj.getClient();
           result[3]=obj.getVersion();
           result[4]=obj.getIp();
           result[5]=obj.getStatus() + ""; 
           return result;
           })
           .list(ExcelWriteStyleTest.getList())// 默認(rèn)情況下導(dǎo)出數(shù)據(jù)達(dá)到excel最大行,自動切換sheet,(xlsx=1048576,xls=65536)
           .list(ExcelWriteStyleTest.getList1())
           .write();
          

          公告模塊框架 framework-common

          包括各種util,例如:日期DateUtil,BigDecimalUtil等等
          

          壓縮框架 framework-compress

          提供各種壓縮方式
          1.bzip2
          2.gzip
          3.jar
          4.tar
          5.zip
          6.zlib
          7.shell命令(gzip,targz)
          

          核心框架 framework-core

          1.整合easyui分頁功能
          2.驗(yàn)證碼
          3.整合easyui樹結(jié)構(gòu)
          4.統(tǒng)一前端請求后的返回參數(shù)
          5.發(fā)送郵件,包括html郵件
          

          db操作框架 framework-database

          封裝操作數(shù)據(jù)庫的基本操作(增刪改查)
          

          異常體系框架 framework-exception

          1.mysql數(shù)據(jù)庫返回的錯誤信息,轉(zhuǎn)成可識別信息
          2.oracle數(shù)據(jù)庫返回的錯誤信息,轉(zhuǎn)成可識別信息
          3.通用的異常返回的錯誤信息,轉(zhuǎn)成可識別信息
          

          文件處理框架 framework-file

          1.ftp
          2.nfs
          

          net框架 framework-net

          1.ftp
          2.sftp
          

          poi框架 framework-poi

          1.csv讀取及下載
          2.excel讀取
          

          加密解密框架 framework-security

          1.不可逆:base64,MD5
          2.對稱密鑰:AES,DES,3DES
          3.非對稱密鑰:RSA
          

          framework-filter

          1、支持切面過濾
          2、和spring環(huán)境集成
           配置方式是:
           web.xml 
           <filter>
           <filter-name>frameworkFilter</filter-name>
           <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
           <init-param>
           <param-name>targetFilterLifecycle</param-name>
           <param-value>true</param-value>
           </init-param>
           </filter>
           <filter-mapping>
           <filter-name>frameworkFilter</filter-name>
           <url-pattern>/*</url-pattern>
           </filter-mapping>
           spring 配置文件
           <bean id="frameworkFilter" class="cn.vanskey.filter.web.FrameworkFilterFactoryBean">
           <property name="filters"> //過濾器配置
           <util:map>
           <entry key="myfilter">
           <bean class="com.zrj.pay.cashier.action.demo.MyFilter"/>
           </entry>
           </util:map>
           </property>
           <property name="filterChainDefinitions">
           <value>
           /**=myfilter //過濾器和路徑的對應(yīng)關(guān)系
           </value>
           </property>
           </bean>
          

          關(guān)注后私信“FrameworkPoi”就會收到詳細(xì)文檔介紹,喜歡的關(guān)注下每天會推出更多技術(shù)精品。


          主站蜘蛛池模板: 亚洲一区二区三区香蕉| 久久精品成人一区二区三区| 国产精品分类视频分类一区| 国产一区二区影院| 亚洲熟妇av一区二区三区下载| 无码精品人妻一区二区三区免费 | 亚洲一区电影在线观看| av无码人妻一区二区三区牛牛 | 国产视频一区二区| 97久久精品无码一区二区天美| 日韩精品成人一区二区三区| 狠狠综合久久AV一区二区三区| 在线观看国产一区二区三区| 亚洲一区二区三区久久| 一区二区三区日韩| 无码精品人妻一区二区三区漫画 | 精品伦精品一区二区三区视频 | 一区二区精品在线观看| 国产乱码精品一区三上| 国产福利一区视频| 日韩在线视频不卡一区二区三区 | AV怡红院一区二区三区| 国产一区精品视频| 精品在线一区二区| 一区在线免费观看| 国产天堂一区二区综合| 红桃AV一区二区三区在线无码AV| 国产一区二区三区高清视频 | 成人国产精品一区二区网站公司| 亚洲AV无码一区二区三区网址| 日本高清一区二区三区| 精品久久久久久中文字幕一区| 国产精品无码一区二区三区免费| 国产一区二区三区樱花动漫| 日韩毛片一区视频免费| 久久精品无码一区二区三区日韩 | 国产一区二区电影在线观看| 另类免费视频一区二区在线观看| 日韩高清国产一区在线 | 在线观看午夜亚洲一区| 一区二区三区日韩|