Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537 Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537 亚洲资源在线视频,久久久久久亚洲精品影院,国产欧美日韩在线视频

          整合營銷服務(wù)商

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

          免費咨詢熱線:

          開源easyHtml-導(dǎo)出html表格文件

          接上篇文章,導(dǎo)出html文件,我對這部分代碼進行優(yōu)化,提交到github上,為初始版本,后面根據(jù)用戶需求與討論,會不斷更新優(yōu)化功能

          介紹

          • 功能

          導(dǎo)出Html 表格文件,簡單易用

          • 地址

          https://github.com/CollectBugs/EasyHtml

          • 項目展示



          總結(jié)

          開發(fā)此項目的靈感來源于一次項目開發(fā),發(fā)現(xiàn)導(dǎo)出html表格文件需求,比較常見,市面上開源、成熟、免費的方案沒有,如果每一家公司,都從零開始開發(fā),耗時又費力,導(dǎo)致開發(fā)周期變長,不如大家開源共建此項目,讓后來人站在巨人的肩膀上進行開發(fā)與維護,共享資源,其樂而不為,希望大家多多給與關(guān)注與討論哦!

          每天不斷更,精彩不停止,明天見,我是行者

          記得留個關(guān)注、點贊、評論喲,讓我們一起去看星辰大海,品味代碼人生

          、nuget 引用

          Select.HtmlToPdf

          2、方法

          • using SelectPdf;using System.Collections.Specialized;using System.IO;using System.Web;
            namespace BQoolCommon.Helpers.File{ public class WebToPdf { public WebToPdf() { //SelectPdf.GlobalProperties.LicenseKey = "your-license-key"; }
            /// <summary> /// 將 Html 轉(zhuǎn)成 PDF,並儲存成檔案 /// </summary> /// <param name="html">html</param> /// <param name="fileName">絕對路徑</param> public void SaveToFileByHtml(string html, string fileName) { var doc = SetPdfDocument(html); doc.Save(fileName); }
            /// <summary> /// 傳入 Url 轉(zhuǎn)成 PDF,並儲存成檔案 /// </summary> /// <param name="url">url</param> /// <param name="fileName">絕對路徑</param> /// <param name="httpCookies">Cookies</param> public void SaveToFileByUrl(string url, string fileName, NameValueCollection httpCookies) { var doc = SetPdfDocument(url, httpCookies); doc.Save(fileName); }
            /// <summary> /// 將 Html 轉(zhuǎn)成 PDF,並輸出成 byte[] 格式 /// </summary> /// <param name="html">html</param> /// <returns></returns> public byte[] GetFileByteByHtml(string html) { var doc = SetPdfDocument(html); return doc.Save(); }
            /// <summary> /// 傳入 Url 轉(zhuǎn)成 PDF,並輸出成 byte[] 格式 /// </summary> /// <param name="url">url</param> /// <param name="httpCookies">Cookies</param> /// <returns></returns> public byte[] GetFileByteByUrl(string url, NameValueCollection httpCookies) { var doc = SetPdfDocument(url, httpCookies); return doc.Save(); }
            /// <summary> /// 將 Html 轉(zhuǎn)成 PDF,並輸出成 Stream 格式 /// </summary> /// <param name="html">html</param> /// <returns></returns> public Stream GetFileStreamByHtml(string html) { var doc = SetPdfDocument(html); var pdfStream = new MemoryStream();
            doc.Save(pdfStream); pdfStream.Position = 0;
            return pdfStream; }
            /// <summary> /// 傳入 Url 轉(zhuǎn)成 PDF,並輸出成 Stream 格式 /// </summary> /// <param name="html">html</param> /// <returns></returns> public Stream GetFileStreamByUrl(string url, NameValueCollection httpCookies) { var doc = SetPdfDocument(url, httpCookies); var pdfStream = new MemoryStream();
            doc.Save(pdfStream); pdfStream.Position = 0;
            return pdfStream; }
            private PdfDocument SetPdfDocument(string html) { var converter = new HtmlToPdf();
            converter.Options.WebPageWidth = 1200; html = HttpUtility.HtmlDecode(html);
            return converter.ConvertHtmlString(html); }
            private PdfDocument SetPdfDocument(string url, NameValueCollection httpCookies) { var converter = new HtmlToPdf(); converter.Options.WebPageWidth = 1200;
            if (httpCookies != && httpCookies.Count != 0) { converter.Options.HttpCookies.Add(httpCookies); }
            return converter.ConvertUrl(url); }
            }}

          目中用到需要將頁面數(shù)據(jù)導(dǎo)出 就想到了IE的直接導(dǎo)出。

          將用到的示例給大家分享一下:

          //將表格中的數(shù)據(jù)導(dǎo)出到excel中

          function exportDataToExcel(tid){

          var curTbl = $('#tid');

          var oXLn;

          try{

          oXLn = new ActiveXObject("Excel.Application"); //創(chuàng)建對象excel

          }catch(e){

          alert("無法啟動Excel!\n\n如果您確信您的電腦中已經(jīng)安裝了Excel,"+"那么請調(diào)整IE的安全級別。\n\n具體操作:\n\n"+"工具 → Internet選項 → 安全 → 自定義級別 → 對沒有標(biāo)記為安全的ActiveX進行初始化和腳本運行 → 啟用");

          return false;

          }

          var oWBs = oXLn.Workbooks.Add(); //獲取workbook對象

          var oSheet1 = oWBs.ActiveSheet;//激活當(dāng)前sheet

          var sel = document.body.createTextRange();

          sel.moveToElementText(curTbl); //把表格中的內(nèi)容移到TextRange中

          sel.select(); //全選TextRange中內(nèi)容

          sel.execCommand("Copy");//復(fù)制TextRange中內(nèi)容

          oSheet1.Paste();//粘貼到活動的EXCEL中

          oXLn.Visible = true; //設(shè)置excel可見屬性

          var fname = oXLn.Application.GetSaveAsFilename("將table導(dǎo)出到excel.xls", "Excel Spreadsheets (*.xls), *.xls");

          oWBs.SaveAs(fname);

          oWBs.Close();

          oXLn.nQuit();

          }

          注意:1.電腦必須安裝微軟的excel。

          2.需要將瀏覽器的active控件設(shè)置為啟用。


          主站蜘蛛池模板: 午夜一区二区在线观看| 天码av无码一区二区三区四区| 国产精品视频一区二区噜噜| 变态拳头交视频一区二区 | 久久精品无码一区二区三区日韩| 亚洲国产精品第一区二区三区| 国产精品久久久久一区二区| 国产主播一区二区三区在线观看| 四虎精品亚洲一区二区三区 | 亚洲AV无码一区二区三区DV| 亚洲香蕉久久一区二区| 亚洲AV无码一区二区三区性色| 成人一区专区在线观看| 国产精品乱码一区二区三区| 色妞色视频一区二区三区四区| 日本一区二区三区四区视频| 亚洲色欲一区二区三区在线观看| 国产精品揄拍一区二区| 综合激情区视频一区视频二区| 亚洲一区二区三区香蕉| 天堂一区人妻无码| 国模大尺度视频一区二区| 无码人妻精品一区二区三区蜜桃| 无码日韩精品一区二区人妻 | 亚洲一区无码精品色| 无码人妻一区二区三区免费看| 人妻互换精品一区二区| 最美女人体内射精一区二区| 尤物精品视频一区二区三区| 红杏亚洲影院一区二区三区| 日韩成人无码一区二区三区| 国模无码人体一区二区| 四虎成人精品一区二区免费网站| 奇米精品一区二区三区在线观看| 国产精品无码一区二区三区毛片| 好看的电影网站亚洲一区| 日韩动漫av在线播放一区| 亚洲AV日韩AV一区二区三曲| 无码人妻一区二区三区免费n鬼沢 无码人妻一区二区三区免费看 | 激情内射亚洲一区二区三区| 精品福利一区二区三区精品国产第一国产综合精品 |