From 308ace406fa3a75c128d225ff915ae5ba349d643 Mon Sep 17 00:00:00 2001 From: libo Date: Thu, 9 Mar 2023 11:01:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=A8=E9=99=A2=E8=AF=BE=E7=A8=8B=E8=A1=A8?= =?UTF-8?q?=E5=AF=BC=E5=87=BA=E4=B8=BAword?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Views/TimeTable/IndexInEducation.cshtml | 122 ++++++++----- .../Views/TimeTable/IndexInEducation.js | 10 +- .../Content/js/FileSaver.js | 172 ++++++++++++++++++ .../Content/js/jquery.wordexport.js | 84 +++++++++ 4 files changed, 341 insertions(+), 47 deletions(-) create mode 100644 Learun.Framework.Ultimate V7/Learun.Application.Web/Content/js/FileSaver.js create mode 100644 Learun.Framework.Ultimate V7/Learun.Application.Web/Content/js/jquery.wordexport.js diff --git a/Learun.Framework.Ultimate V7/Learun.Application.Web/Areas/PersonnelManagement/Views/TimeTable/IndexInEducation.cshtml b/Learun.Framework.Ultimate V7/Learun.Application.Web/Areas/PersonnelManagement/Views/TimeTable/IndexInEducation.cshtml index 3b82817c5..ee41cc9e7 100644 --- a/Learun.Framework.Ultimate V7/Learun.Application.Web/Areas/PersonnelManagement/Views/TimeTable/IndexInEducation.cshtml +++ b/Learun.Framework.Ultimate V7/Learun.Application.Web/Areas/PersonnelManagement/Views/TimeTable/IndexInEducation.cshtml @@ -62,12 +62,12 @@ border-right: 1px solid #333; } - .perWeek li { - width: 12.5%; - float: left; - border-left: 1px solid #333; - height: 100%; - } + .perWeek li { + width: 12.5%; + float: left; + border-left: 1px solid #333; + height: 100%; + } .perFestivalsBox { border-left: 1px solid #333; @@ -76,29 +76,28 @@ text-align: center; } - .perFestivalsBox table { - display: block; - width: 100%; - text-align: center; - } - - .perFestivalsBox td { - border-left: 1px solid #333; - border-top: 1px solid #333; - padding: 1px; - width: 12.5%; - font-size: 12px; - } - - .perFestivalsBox td div { - min-height: 16px; - line-height: 16px; - } - - .perFestivalsBox td:first-child, .perWeek li:first-child { - border-left: 0; - } - + .perFestivalsBox table { + display: block; + width: 100%; + text-align: center; + } + + .perFestivalsBox td { + border-left: 1px solid #333; + border-top: 1px solid #333; + padding: 1px; + width: 12.5%; + font-size: 12px; + } + + .perFestivalsBox td div { + min-height: 16px; + line-height: 16px; + } + + .perFestivalsBox td:first-child, .perWeek li:first-child { + border-left: 0; + } \n\n", + body: "_body_" + } + }; + var options = { + maxWidth: 624 + }; + // Clone selected element before manipulating it + var markup = $(this).clone(); + + // Remove hidden elements from the output + markup.each(function() { + var self = $(this); + if (self.is(':hidden')) + self.remove(); + }); + + // Embed all images using Data URLs + var images = Array(); + var img = markup.find('img'); + for (var i = 0; i < img.length; i++) { + // Calculate dimensions of output image + var w = Math.min(img[i].width, options.maxWidth); + var h = img[i].height * (w / img[i].width); + // Create canvas for converting image to data URL + var canvas = document.createElement("CANVAS"); + canvas.width = w; + canvas.height = h; + // Draw image to canvas + var context = canvas.getContext('2d'); + context.drawImage(img[i], 0, 0, w, h); + // Get data URL encoding of image + var uri = canvas.toDataURL("image/png"); + $(img[i]).attr("src", img[i].src); + img[i].width = w; + img[i].height = h; + // Save encoded image to array + images[i] = { + type: uri.substring(uri.indexOf(":") + 1, uri.indexOf(";")), + encoding: uri.substring(uri.indexOf(";") + 1, uri.indexOf(",")), + location: $(img[i]).attr("src"), + data: uri.substring(uri.indexOf(",") + 1) + }; + } + + // Prepare bottom of mhtml file with image data + var mhtmlBottom = "\n"; + for (var i = 0; i < images.length; i++) { + mhtmlBottom += "--NEXT.ITEM-BOUNDARY\n"; + mhtmlBottom += "Content-Location: " + images[i].location + "\n"; + mhtmlBottom += "Content-Type: " + images[i].type + "\n"; + mhtmlBottom += "Content-Transfer-Encoding: " + images[i].encoding + "\n\n"; + mhtmlBottom += images[i].data + "\n\n"; + } + mhtmlBottom += "--NEXT.ITEM-BOUNDARY--"; + + //TODO: load css from included stylesheet + var styles = ""; + + // Aggregate parts of the file together + var fileContent = static.mhtml.top.replace("_html_", static.mhtml.head.replace("_styles_", styles) + static.mhtml.body.replace("_body_", markup.html())) + mhtmlBottom; + + // Create a Blob with the file contents + var blob = new Blob([fileContent], { + type: "application/msword;charset=utf-8" + }); + saveAs(blob, fileName + ".doc"); + }; + })(jQuery); +} else { + if (typeof jQuery === "undefined") { + console.error("jQuery Word Export: missing dependency (jQuery)"); + } + if (typeof saveAs === "undefined") { + console.error("jQuery Word Export: missing dependency (FileSaver.js)"); + } +}