From b193fadd72290ed6ce83ec11b7317f9c7cec9afd Mon Sep 17 00:00:00 2001 From: "Namhyeon, Go" Date: Sat, 1 Jun 2024 06:58:11 +0900 Subject: [PATCH] Update lib/msoffice, Create lib/filetypes.js and data --- data/filetypes.json | 57 +++++++++++++++++++++ lib/filetypes.js | 26 ++++++++++ lib/msoffice.js | 121 +++++--------------------------------------- 3 files changed, 95 insertions(+), 109 deletions(-) create mode 100644 data/filetypes.json create mode 100644 lib/filetypes.js diff --git a/data/filetypes.json b/data/filetypes.json new file mode 100644 index 0000000..ad6863b --- /dev/null +++ b/data/filetypes.json @@ -0,0 +1,57 @@ +[ + {"extension": [".xlsx"], "type": ["Excel Workbook"], "openwith": ["msexcel"]}, + {"extension": [".xlsm"], "type": ["Excel Macro-Enabled Workbook (code)"], "openwith": ["msexcel"]}, + {"extension": [".xlsb"], "type": ["Excel Binary Workbook"], "openwith": ["msexcel"]}, + {"extension": [".xltx"], "type": ["Template"], "openwith": ["msexcel"]}, + {"extension": [".xltm"], "type": ["Template (code)"], "openwith": ["msexcel"]}, + {"extension": [".xls"], "type": ["Excel 97- Excel 2003 Workbook", "Microsoft Excel 5.0/95 Workbook", "Microsoft Excel file formats"], "openwith": ["msexcel"]}, + {"extension": [".xlt"], "type": ["Excel 97- Excel 2003 Template"], "openwith": ["msexcel"]}, + {"extension": [".xml"], "type": ["XML Spreadsheet 2003", "XML Data", "Word 2003 XML Document", "Word XML Document"], "openwith": ["msexcel", "msword"]}, + {"extension": [".xlam"], "type": ["Excel Add-In"], "openwith": ["msexcel"]}, + {"extension": [".xla"], "type": ["Excel 97-2003 Add-In"], "openwith": ["msexcel"]}, + {"extension": [".xlw"], "type": ["Excel 4.0 Workbook"], "openwith": ["msexcel"]}, + {"extension": [".xlr"], "type": ["Works 6.0-9.0 spreadsheet"], "openwith": ["msexcel"]}, + {"extension": [".prn"], "type": ["Formatted Text (Space-delimited)"], "openwith": ["msexcel"]}, + {"extension": [".txt"], "type": ["Text (Tab-delimited)", "Text (Macintosh)", "Text (MS-DOS)", "Unicode Text", "Text (tab-delimited)", "Plain Text", "Text"], "openwith": ["msexcel", "msword"]}, + {"extension": [".csv"], "type": ["CSV (comma delimited)", "CSV (Macintosh)", "CSV (MS-DOS)", "CSV (Comma-delimited)"], "openwith": ["msexcel"]}, + {"extension": [".dif"], "type": ["DIF"], "openwith": ["msexcel"]}, + {"extension": [".slk"], "type": ["SYLK"], "openwith": ["msexcel"]}, + {"extension": [".dbf"], "type": ["DBF 3, DBF 4"], "openwith": ["msexcel"]}, + {"extension": [".ods"], "type": ["OpenDocument Spreadsheet"], "openwith": ["msexcel"]}, + {"extension": [".pdf"], "type": ["PDF", "PDF Document Format"], "openwith": ["msexcel", "msppt", "msword"]}, + {"extension": [".xps"], "type": ["XPS Document", "XPS Document Format"], "openwith": ["msexcel", "msppt", "msword"]}, + {"extension": [".wmf", ".emf"], "type": ["Picture", "Windows Metafile", "Enhanced Windows Metafile"], "openwith": ["msexcel", "msppt"]}, + {"extension": [".bmp"], "type": ["Bitmap", "Device Independent Bitmap"], "openwith": ["msexcel", "msppt"]}, + {"extension": [".rtf"], "type": ["Formatted text (Space-delimited)", "Rich Text Format", "Outline/RTF"], "openwith": ["msexcel", "msppt", "msword"]}, + {"extension": [".gif", ".jpg", ".doc", ".xls", ".bmp"], "type": ["Embedded object", "Linked object"], "openwith": ["msexcel"]}, + {"extension": [".emf"], "type": ["Office drawing object"], "openwith": ["msexcel"]}, + {"extension": [".mht", ".mhtml"], "type": ["Single File Web Page", "Web Page, Filtered"], "openwith": ["msexcel", "msppt", "msword"]}, + {"extension": [".htm", ".html"], "type": ["Web Page", "Web Page, Filtered"], "openwith": ["msexcel", "msppt", "msword"]}, + {"extension": [".pptx"], "type": ["PowerPoint Presentation", "PowerPoint Picture Presentation", "Strict Open XML Presentation"], "openwith": ["msppt"]}, + {"extension": [".pptm"], "type": ["PowerPoint Macro-Enabled Presentation"], "openwith": ["msppt"]}, + {"extension": [".ppt"], "type": ["PowerPoint 97-2003 Presentation"], "openwith": ["msppt"]}, + {"extension": [".potx"], "type": ["PowerPoint Design Templates"], "openwith": ["msppt"]}, + {"extension": [".potm"], "type": ["PowerPoint Macro-Enabled Design Template"], "openwith": ["msppt"]}, + {"extension": [".pot"], "type": ["PowerPoint 97-2003 Design Template"], "openwith": ["msppt"]}, + {"extension": [".thmx"], "type": ["Office Theme"], "openwith": ["msppt"]}, + {"extension": [".ppsx"], "type": ["PowerPoint Show"], "openwith": ["msppt"]}, + {"extension": [".ppsm"], "type": ["PowerPoint Macro-Enabled Show"], "openwith": ["msppt"]}, + {"extension": [".pps"], "type": ["PowerPoint 97-2003 Show"], "openwith": ["msppt"]}, + {"extension": [".ppam"], "type": ["PowerPoint Add-In"], "openwith": ["msppt"]}, + {"extension": [".ppa"], "type": ["PowerPoint 97-2003 Add-In"], "openwith": ["msppt"]}, + {"extension": [".xml"], "type": ["PowerPoint XML Presentation"], "openwith": ["msppt"]}, + {"extension": [".mp4"], "type": ["MPEG-4 Video"], "openwith": ["msppt"]}, + {"extension": [".wmv"], "type": ["Windows Media Video"], "openwith": ["msppt"]}, + {"extension": [".gif"], "type": ["GIF (Graphics Interchange Format)"], "openwith": ["msppt"]}, + {"extension": [".jpg"], "type": ["JPEG (Joint Photographic Experts Group) FileFormat"], "openwith": ["msppt"]}, + {"extension": [".png"], "type": ["PNG (Portable Network Graphics) Format"], "openwith": ["msppt"]}, + {"extension": [".tif"], "type": ["TIFF (Tag Image File Format)"], "openwith": ["msppt"]}, + {"extension": [".doc"], "type": ["Word 97-2003 Document"], "openwith": ["msword"]}, + {"extension": [".docm"], "type": ["Word Macro-Enabled Document"], "openwith": ["msword"]}, + {"extension": [".docx"], "type": ["Word Document", "Strict Open XML Document"], "openwith": ["msword"]}, + {"extension": [".dot"], "type": ["Word 97-2003 Template"], "openwith": ["msword"]}, + {"extension": [".dotm"], "type": ["Word Macro-Enabled Template"], "openwith": ["msword"]}, + {"extension": [".dotx"], "type": ["Word Template"], "openwith": ["msword"]}, + {"extension": [".odt"], "type": ["OpenDocument Text"], "openwith": ["msword"]}, + {"extension": [".wps"], "type": ["Works 6-9 Document"], "openwith": ["msword"]} +] diff --git a/lib/filetypes.js b/lib/filetypes.js new file mode 100644 index 0000000..a953736 --- /dev/null +++ b/lib/filetypes.js @@ -0,0 +1,26 @@ +// msoffice.js +// Namhyeon Go +// https://github.com/gnh1201/welsonjs + +var FILE = require("lib/file"); + +// https://support.microsoft.com/en-au/office/file-formats-that-are-supported-in-excel-0943ff2c-6014-4e8d-aaea-b83d51d46247 +// https://support.microsoft.com/en-au/office/file-formats-that-are-supported-in-powerpoint-252c6fa0-a4bc-41be-ac82-b77c9773f9dc +// https://learn.microsoft.com/en-us/deployoffice/compat/office-file-format-reference#file-formats-that-are-supported-in-word +var data = JSON.parse(FILE.readFile("data/filetypes.json", FILE.CdoCharset.CdoUTF_8)); + +function getExtensionsByOpenWith(openwith) { + return data.reduce(function(a, x) { + if (x.openwith && x.openwith.indexOf(openwith) !== -1) { + return a.concat(x.extension); + } + return a; + }, []); +} + +exports.getExtensionsByOpenWith = getExtensionsByOpenWith; + +exports.VERSIONINFO = "FileTypes version 0.0.1"; +exports.AUTHOR = "abuse@catswords.net"; +exports.global = global; +exports.require = global.require; diff --git a/lib/msoffice.js b/lib/msoffice.js index 8aeadc8..db91980 100644 --- a/lib/msoffice.js +++ b/lib/msoffice.js @@ -4,110 +4,7 @@ var STD = require("lib/std"); var SYS = require("lib/system"); var FILE = require("lib/file"); - -var FileTypes = {}; - -// https://support.microsoft.com/en-au/office/file-formats-that-are-supported-in-excel-0943ff2c-6014-4e8d-aaea-b83d51d46247 -FileTypes.Excel = [ - {"extension": [".xlsx"], "type": "Excel Workbook"}, - {"extension": [".xlsm"], "type": "Excel Macro-Enabled Workbook (code)"}, - {"extension": [".xlsb"], "type": "Excel Binary Workbook"}, - {"extension": [".xltx"], "type": "Template"}, - {"extension": [".xltm"], "type": "Template (code)"}, - {"extension": [".xls"], "type": "Excel 97- Excel 2003 Workbook"}, - {"extension": [".xlt"], "type": "Excel 97- Excel 2003 Template"}, - {"extension": [".xls"], "type": "Microsoft Excel 5.0/95 Workbook"}, - {"extension": [".xml"], "type": "XML Spreadsheet 2003"}, - {"extension": [".xml"], "type": "XML Data"}, - {"extension": [".xlam"], "type": "Excel Add-In"}, - {"extension": [".xla"], "type": "Excel 97-2003 Add-In"}, - {"extension": [".xlw"], "type": "Excel 4.0 Workbook"}, - {"extension": [".xlr"], "type": "Works 6.0-9.0 spreadsheet"}, - {"extension": [".prn"], "type": "Formatted Text (Space-delimited)"}, - {"extension": [".txt"], "type": "Text (Tab-delimited)"}, - {"extension": [".txt"], "type": "Text (Macintosh)"}, - {"extension": [".txt"], "type": "Text (MS-DOS)"}, - {"extension": [".txt"], "type": "Unicode Text"}, - {"extension": [".csv"], "type": "CSV (comma delimited)"}, - {"extension": [".csv"], "type": "CSV (Macintosh)"}, - {"extension": [".csv"], "type": "CSV (MS-DOS)"}, - {"extension": [".dif"], "type": "DIF"}, - {"extension": [".slk"], "type": "SYLK"}, - {"extension": [".dbf"], "type": "DBF 3, DBF 4"}, - {"extension": [".ods"], "type": "OpenDocument Spreadsheet"}, - {"extension": [".pdf"], "type": "PDF"}, - {"extension": [".xps"], "type": "XPS Document"}, - {"extension": [".wmf", ".emf"], "type": "Picture"}, - {"extension": [".bmp"], "type": "Bitmap"}, - {"extension": [".xls"], "type": "Microsoft Excel file formats"}, - {"extension": [".slk"], "type": "SYLK"}, - {"extension": [".dif"], "type": "DIF"}, - {"extension": [".txt"], "type": "Text (tab-delimited)"}, - {"extension": [".csv"], "type": "CSV (Comma-delimited)"}, - {"extension": [".rtf"], "type": "Formatted text (Space-delimited)"}, - {"extension": [".gif", ".jpg", ".doc", ".xls", ".bmp"], "type": "Embedded object"}, - {"extension": [".gif", ".jpg", ".doc", ".xls", ".bmp"], "type": "Linked object"}, - {"extension": [".emf"], "type": "Office drawing object"}, - {"extension": [".txt"], "type": "Text"}, - {"extension": [".mht", ".mhtml"], "type": "Single File Web Page"}, - {"extension": [".htm", ".html"], "type": "Web Page"} -]; - -// https://support.microsoft.com/en-au/office/file-formats-that-are-supported-in-powerpoint-252c6fa0-a4bc-41be-ac82-b77c9773f9dc -FileTypes.PowerPoint = [ - {"extension": [".pptx"], "type": "PowerPoint Presentation"}, - {"extension": [".pptm"], "type": "PowerPoint Macro-Enabled Presentation"}, - {"extension": [".ppt"], "type": "PowerPoint 97-2003 Presentation"}, - {"extension": [".pdf"], "type": "PDF Document Format"}, - {"extension": [".xps"], "type": "XPS Document Format"}, - {"extension": [".potx"], "type": "PowerPoint Design Templates"}, - {"extension": [".potm"], "type": "PowerPoint Macro-Enabled Design Template"}, - {"extension": [".pot"], "type": "PowerPoint 97-2003 Design Template"}, - {"extension": [".thmx"], "type": "Office Theme"}, - {"extension": [".ppsx"], "type": "PowerPoint Show"}, - {"extension": [".ppsm"], "type": "PowerPoint Macro-Enabled Show"}, - {"extension": [".pps"], "type": "PowerPoint 97-2003 Show"}, - {"extension": [".ppam"], "type": "PowerPoint Add-In"}, - {"extension": [".ppa"], "type": "PowerPoint 97-2003 Add-In"}, - {"extension": [".xml"], "type": "PowerPoint XML Presentation"}, - {"extension": [".mp4"], "type": "MPEG-4 Video"}, - {"extension": [".wmv"], "type": "Windows Media Video"}, - {"extension": [".gif"], "type": "GIF (Graphics Interchange Format)"}, - {"extension": [".jpg"], "type": "JPEG (Joint Photographic Experts Group) FileFormat"}, - {"extension": [".png"], "type": "PNG (Portable Network Graphics) Format"}, - {"extension": [".tif"], "type": "TIFF (Tag Image File Format)"}, - {"extension": [".bmp"], "type": "Device Independent Bitmap"}, - {"extension": [".wmf"], "type": "Windows Metafile"}, - {"extension": [".emf"], "type": "Enhanced Windows Metafile"}, - {"extension": [".rtf"], "type": "Outline/RTF"}, - {"extension": [".pptx"], "type": "PowerPoint Picture Presentation"}, - {"extension": [".pptx"], "type": "Strict Open XML Presentation"}, - {"extension": [".odp"], "type": "OpenDocument Presentation"}, - {"extension": [".mht", ".mhtml"], "type": "Single File Web Page"}, - {"extension": [".htm", ".html"], "type": "Web Page"} -]; - -// https://learn.microsoft.com/en-us/deployoffice/compat/office-file-format-reference#file-formats-that-are-supported-in-word -FileTypes.Word = [ - {"extension": [".doc"], "type": "Word 97-2003 Document"}, - {"extension": [".docm"], "type": "Word Macro-Enabled Document"}, - {"extension": [".docx"], "type": "Word Document"}, - {"extension": [".docx"], "type": "Strict Open XML Document"}, - {"extension": [".dot"], "type": "Word 97-2003 Template"}, - {"extension": [".dotm"], "type": "Word Macro-Enabled Template"}, - {"extension": [".dotx"], "type": "Word Template"}, - {"extension": [".htm", ".html"], "type": "Web Page"}, - {"extension": [".htm", ".html"], "type": "Web Page, Filtered"}, - {"extension": [".mht", ".mhtml"], "type": "Single File Web Page"}, - {"extension": [".odt"], "type": "OpenDocument Text"}, - {"extension": [".pdf"], "type": "PDF"}, - {"extension": [".rtf"], "type": "Rich Text Format"}, - {"extension": [".txt"], "type": "Plain Text"}, - {"extension": [".wps"], "type": "Works 6-9 Document"}, - {"extension": [".xml"], "type": "Word 2003 XML Document"}, - {"extension": [".xml"], "type": "Word XML Document"}, - {"extension": [".xps"], "type": "XPS Document"} -]; +var FileTypes = require("lib/filetypes"); // EXAMPLE: new Office.Excel() function Excel() { @@ -187,7 +84,6 @@ function Excel() { return new Excel.Cell(this.currentWorksheet.Cells(row, col)); }; }; -Excel.SupportedFileTypes = FileTypes.Excel; Excel.Range = function(range) { this.range = range; this.getCellByPosition = function(row, col) { @@ -214,6 +110,7 @@ Excel.Cell = function(cell) { return this.call.Formula; } }; +Excel.FileExtensions = FileTypes.getExtensionsByOpenWith("msexcel"); // EXAMPLE: new Office.PowerPoint() function PowerPoint() { @@ -237,7 +134,13 @@ function PowerPoint() { } }; } -PowerPoint.SupportedFileTypes = FileTypes.PowerPoint; +PowerPoint.Slide = function(slide) { + this.slide = slide; +}; +PowerPoint.Shape = function(shape) { + this.shape = shape; +} +PowerPoint.FileExtensions = FileTypes.getExtensionsByOpenWith("msppt"); // EXAMPLE: new Office.Word() function Word() { @@ -246,7 +149,7 @@ function Word() { this.application.Visible = true; console.info("Microsoft Office Word", this.version); - + this.open = function(filename) { if (typeof filename !== "undefined") { // check type of the path @@ -261,13 +164,13 @@ function Word() { } }; } -Word.SupportedFileTypes = FileTypes.Word; +Word.FileExtensions = FileTypes.getExtensionsByOpenWith("msword"); exports.Excel = Excel; exports.PowerPoint = PowerPoint; exports.Word = Word; -exports.VERSIONINFO = "Microsoft Office interface (msoffice.js) version 0.1.9"; +exports.VERSIONINFO = "Microsoft Office interface (msoffice.js) version 0.2.0"; exports.AUTHOR = "abuse@catswords.net"; exports.global = global; exports.require = global.require;