officeparser 2.3.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CODE_OF_CONDUCT.md +76 -76
- package/LICENSE +21 -21
- package/README.md +324 -323
- package/officeParser.js +550 -583
- package/package.json +42 -42
- package/supportedExtensions.js +10 -0
- package/test/createContentTxt.js +27 -0
- package/test/files/test.docx +0 -0
- package/test/files/test.docx.txt +1 -0
- package/test/files/test.odp +0 -0
- package/test/files/test.odp.txt +1 -0
- package/test/files/test.ods +0 -0
- package/test/files/test.ods.txt +1 -0
- package/test/files/test.odt +0 -0
- package/test/files/test.odt.txt +1 -0
- package/test/files/test.pptx +0 -0
- package/test/files/test.pptx.txt +1 -0
- package/test/files/test.xlsx +0 -0
- package/test/files/test.xlsx.txt +1 -0
- package/test/testOfficeParser.js +97 -0
- package/.vscode/settings.json +0 -3
package/package.json
CHANGED
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "officeparser",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "A Node.js library to parse text out of any office file. Currently supports docx, pptx, xlsx, odt, odp and ods files.",
|
|
5
|
-
"main": "officeParser.js",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"test": "
|
|
8
|
-
},
|
|
9
|
-
"repository": {
|
|
10
|
-
"type": "git",
|
|
11
|
-
"url": "git+https://github.com/harshankur/officeParser.git"
|
|
12
|
-
},
|
|
13
|
-
"keywords": [
|
|
14
|
-
"office",
|
|
15
|
-
"docx",
|
|
16
|
-
"pptx",
|
|
17
|
-
"xlsx",
|
|
18
|
-
"odt",
|
|
19
|
-
"odp",
|
|
20
|
-
"ods",
|
|
21
|
-
"parser",
|
|
22
|
-
"text",
|
|
23
|
-
"extract text",
|
|
24
|
-
"document",
|
|
25
|
-
"word",
|
|
26
|
-
"excel",
|
|
27
|
-
"worksheet",
|
|
28
|
-
"powerpoint",
|
|
29
|
-
"slides"
|
|
30
|
-
],
|
|
31
|
-
"author": "Harsh Ankur",
|
|
32
|
-
"license": "MIT",
|
|
33
|
-
"bugs": {
|
|
34
|
-
"url": "https://github.com/harshankur/officeParser/issues"
|
|
35
|
-
},
|
|
36
|
-
"homepage": "https://github.com/harshankur/officeParser#readme",
|
|
37
|
-
"dependencies": {
|
|
38
|
-
"decompress": "^4.2.0",
|
|
39
|
-
"rimraf": "^2.6.3",
|
|
40
|
-
"xml2js": "^0.4.19"
|
|
41
|
-
}
|
|
42
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "officeparser",
|
|
3
|
+
"version": "3.0.0",
|
|
4
|
+
"description": "A Node.js library to parse text out of any office file. Currently supports docx, pptx, xlsx, odt, odp and ods files.",
|
|
5
|
+
"main": "officeParser.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "node test/testOfficeParser.js"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/harshankur/officeParser.git"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"office",
|
|
15
|
+
"docx",
|
|
16
|
+
"pptx",
|
|
17
|
+
"xlsx",
|
|
18
|
+
"odt",
|
|
19
|
+
"odp",
|
|
20
|
+
"ods",
|
|
21
|
+
"parser",
|
|
22
|
+
"text",
|
|
23
|
+
"extract text",
|
|
24
|
+
"document",
|
|
25
|
+
"word",
|
|
26
|
+
"excel",
|
|
27
|
+
"worksheet",
|
|
28
|
+
"powerpoint",
|
|
29
|
+
"slides"
|
|
30
|
+
],
|
|
31
|
+
"author": "Harsh Ankur",
|
|
32
|
+
"license": "MIT",
|
|
33
|
+
"bugs": {
|
|
34
|
+
"url": "https://github.com/harshankur/officeParser/issues"
|
|
35
|
+
},
|
|
36
|
+
"homepage": "https://github.com/harshankur/officeParser#readme",
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"decompress": "^4.2.0",
|
|
39
|
+
"rimraf": "^2.6.3",
|
|
40
|
+
"xml2js": "^0.4.19"
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const officeParser = require("../officeParser");
|
|
2
|
+
const fs = require("fs");
|
|
3
|
+
const supportedExtensions = require("../supportedExtensions");
|
|
4
|
+
|
|
5
|
+
// File names of test files and their text output content
|
|
6
|
+
// test file name style => test.<ext>
|
|
7
|
+
// test content output => test.<ext>.txt
|
|
8
|
+
|
|
9
|
+
/** Get filename for an extension */
|
|
10
|
+
function getFilename(ext, isContentFile = false) {
|
|
11
|
+
return `test/files/test.${ext}` + (isContentFile ? `.txt` : '');
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Create content file the test file with passed extension */
|
|
15
|
+
function createContentFile(ext) {
|
|
16
|
+
return officeParser.parseOfficeAsync(getFilename(ext))
|
|
17
|
+
.then(text => fs.writeFileSync(getFilename(ext, true), text, 'utf8'))
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
process.argv.length == 3
|
|
22
|
+
? supportedExtensions.includes(process.argv[2])
|
|
23
|
+
? createContentFile(process.argv[2])
|
|
24
|
+
.then(() => console.log(`Created text content file for ${process.argv[2]} => ${getFilename(process.argv[2], true)}`))
|
|
25
|
+
.catch((error) => console.error(error))
|
|
26
|
+
: console.error("The requested extension test is not currently available.")
|
|
27
|
+
: console.error("Arguments missing");
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Demonstration of DOCX support in calibre This document demonstrates the ability of the calibre DOCX Input plugin to convert the various typographic features in a Microsoft Word (2007 and newer) document. Convert this document to a modern ebook format, such as AZW3 for Kindles or EPUB for other ebook readers, to see it in action. There is support for images, tables, lists, footnotes, endnotes, links, dropcaps and various types of text and paragraph level formatting. To see the DOCX conversion in action, simply add this file to calibre using the “Add Books” button and then click “ Convert”. Set the output format in the top right corner of the conversion dialog to EPUB or AZW3 and click “OK” . Text Formatting Inline formatting Here, we demonstrate various types of inline text formatting and the use of embedded fonts. Here is some bold, italic, bold-italic, underlined and struck out text. Then, we have a super script and a sub script . Now we see some red , green and blue text. Some text with a yellow highlight . Some text in a box . Some text in inverse video . A paragraph with styled text: subtle emphasis f ollowed by strong text a nd intense emphasis . This paragraph uses document wide styles for styling rather than inline text properties as demonstrated in the previous paragraph — calibre can handle both with equal ease. Fun with fonts This document has embedded the Ubuntu font family. The body text is in the Ubuntu typeface, here is some text in the Ubuntu Mono typeface , notice how every letter has the same width, even i and m . Every embedded font will automatically be embedded in the output ebook during conversion. Paragraph level formatting You can do crazy things with paragraphs, if the urge strikes you. For instance this paragraph is right aligned and has a right border. It has also been given a light gray background. For the lovers of poetry amongst you, paragraphs with hanging indents, like this often come in handy. You can use hanging indents to ensure that a line of poetry retains its individual identity as a line even when the screen is too narrow to display it as a single line. Not only does this paragraph have a hanging indent, it is also has an extra top margin, setting it apart from the preceding paragraph. Tables Tables in Word can vary from the extremely simple to the extremely complex. calibre tries to do its best when converting tables. While you may run into trouble with the occasional table, the vast majority of common cases should be converted very well, as demonstrated in this section. Note that for optimum results, when creating tables in Word, you should set their widths using percentages, rather than absolute units. To the left of this paragraph is a floating two column table with a nice green border and header row. Now let’s look at a fancier table—one with alternating row colors and partial borders. This table is stretched out to take 100% of the available width. Next, we see a table with special formatting in various locations. Notice how the f ormatting for the h eader row and sub header rows is preserved. Source: Fictitious data, for illustration purposes only Next , we have something a little more complex, a nested table, i.e. a table inside another table. Additionally, the inner table has some of its cells merged. The table is displayed horizontally centered. W e end with a fancy calendar, note how much of the original formatting is preserved . Note that this table will only display correctly on relatively wide screens. In general, very wide tables or tables whose cells have fixed width requirements don’t fare well in ebooks. Structural Elements Miscellaneous structural elements you can add to your document, like footnotes, endnotes, dropcaps and the like. Footnotes & Endnotes Footnotes and endnotes are automatically recognized and both are converted to endnotes, with backlinks for maximum ease of use in ebook devices. Dropcaps D rop caps are used to emphasize the leading paragraph at the start of a section. In Word it is possible to s p ecify how many lines of text a drop-cap should use. Because of limitations in ebook technology, this is not possible when converting. Instead, the converted drop cap will use font size and line height to simulate the effect as well as possible. While not as good as the original, the result is usually tolerable. This paragraph has a “D” dropcap set to occupy three lines of text with a font size of 58.5 pts. Depending on the screen width and capabilities of the device you view the book on, this dropcap can look anything from perfect to ugly. Links Two kinds of links are possible, those that refer to an external website and those that refer to locations inside the document itself. Both are supported by calibre. For example, here is a link pointing to the . Then we have a link that points back to the section on in this document. calibre download page paragraph level formatting Table of Contents There are two approaches that calibre takes when generating a Table of Contents. The first is if the Word document has a Table of Contents itself. Provided that the Table of Contents uses hyperlinks, calibre will automatically use it. The levels of the Table of Contents are identified by their left indent, so if you want the ebook to have a multi-level Table of Contents, make sure you create a properly indented Table of Contents in Word. If no Table of Contents is found in the document, then a table of contents is automatically generated from the headings in the document. A heading is identified as something that has the Heading 1 or Heading 2, etc. style applied to it. These headings are turned into a Table of Contents with Heading 1 being the topmost level, Heading 2 the second level and so on. You can see the Table of Contents created by calibre by clicking the Table of Contents button in whatever viewer you are using to view the converted ebook. Demonstration of DOCX support in calibre 1 Text Formatting 2 Inline formatting 2 Fun with fonts 2 Paragraph level formatting 2 Tables 3 Structural Elements 5 Footnotes & Endnotes 5 Dropcaps 5 Links 5 Table of Contents 5 Images 7 Lists 8 Bulleted List 8 Numbered List 8 Multi-level Lists 8 Continued Lists 8 Images Images can be of three main types. Inline images are images that are part of the normal text flow, like this image of a green dot . Inline images do not cause breaks in the text and are usually small in size. The next category of image is a floating image, one that “floats “ on the page and is surrounded by text. Word supports more types of floating images than are possible with current ebook technology, so the conversion maps floating images to simple left and right floats, as you can see with the left and right arrow images on the sides of this paragraph. The final type of image is a “block” image, one that becomes a paragraph on its own and has no text on either side. Below is a centered green dot. Centered images like this are useful for large pictures that should be a focus of attention. Generally, it is not possible to translate the exact positioning of images from a Word document to an ebook. That is because in Word, image positioning is specified in absolute units from the page boundaries. There is no analogous technology in ebooks, so the conversion will usually end up placing the image either centered or floating close to the point in the text where it was inserted , not necessarily where it appears on the page in Word. Lists All types of lists are supported by the conversion, with the exception of lists that use fancy bullets, these get converted to regular bullets. Bulleted List One Two Numbered List One, with a very long line to demonstrate that the hanging indent for the list is working correctly Two Multi-level List s One Two Three Four with a very long line to demonstrate that the hanging indent for the list is working correctly. Five Six A Multi-level list with bullets: One Two This bullet uses an image as the bullet item Four Five Continued Lists One Two An interruption in our regularly scheduled listing, for this essential and very relevant public service announcement. We now resume our normal programming Four ITEM NEEDED Books 1 Pens 3 Pencils 2 Highlighter 2 colors Scissors 1 pair City or Town Point A Point B Point C Point D Point E Point A — Point B 87 — Point C 64 56 — Point D 37 32 91 — Point E 93 35 54 43 — College New students Graduating students Change Undergraduate Cedar University 110 103 +7 Oak Institute 202 210 -8 Graduate Cedar University 24 20 +4 Elm College 43 53 -10 Total 998 908 90 One Three Two Four To the left is a table inside a table, with some cells merged. December 2007 Sun Mon Tue Wed Thu Fri Sat 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Lorem ipsum Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc ac faucibus odio. Vestibulum neque massa, scelerisque sit amet ligula eu, congue molestie mi. Praesent ut varius sem. Nullam at porttitor arcu, nec lacinia nisi. Ut ac dolor vitae odio interdum condimentum. Vivamus dapibus sodales ex, vitae malesuada ipsum cursus convallis. Maecenas sed egestas nulla, ac condimentum orci. Mauris diam felis, vulputate ac suscipit et, iaculis non est. Curabitur semper arcu ac ligula semper, nec luctus nisl blandit. Integer lacinia ante ac libero lobortis imperdiet. Nullam mollis convallis ipsum, ac accumsan nunc vehicula vitae. Nulla eget justo in felis tristique fringilla. Morbi sit amet tortor quis risus auctor condimentum. Morbi in ullamcorper elit. Nulla iaculis tellus sit amet mauris tempus fringilla. Maecenas mauris lectus, lobortis et purus mattis, blandit dictum tellus. Maecenas non lorem quis tellus placerat varius. Nulla facilisi. Aenean congue fringilla justo ut aliquam. Mauris id ex erat. Nunc vulputate neque vitae justo facilisis, non condimentum ante sagittis. Morbi viverra semper lorem nec molestie. Maecenas tincidunt est efficitur ligula euismod, sit amet ornare est vulputate. Chart Table Column 1 Column 2 Column 3 Column 4 Column 5 Photo
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/ / Hello Testing 0 First Name Last Name Gender Country Age Date Id 1 Dulce Abril Female United States 32 15/10/2017 1562 2 Mara Hashimoto Female Great Britain 25 16/08/2016 1582 3 Philip Gent Male France 36 21/05/2015 2587 4 Kathleen Hanner Female United States 25 15/10/2017 3549 5 Nereida Magwood Female United States 58 16/08/2016 2468 96 Roma Lafollette Female United States 34 15/10/2017 2654 97 Felisa Cail Female United States 28 16/08/2016 6525 98 Demetria Abbey Female United States 32 21/05/2015 3265 99 Jeromy Danz Male United States 39 15/10/2017 3265 100 Rasheeda Alkire Female United States 29 16/08/2016 6125
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Text file Digital archaeologists find occasional gems in the vast European information repository. Taken from the mountain of uncatalogued ephemera, this text is written in a style suggesting composition in the early 21st century, possibly even on paper. Diary fragment 1: Dear Diary, Day 1 of our boating holiday on the Sûre in Luxembourg! Up at the crack of dawn to get to the departure point. Ten minutes to learn the ropes and then off we set in our canoes! There was not a breath of wind as we drifted downstream, sometimes passing an angler staring intently at his float, or a group of children paddling. When I commented that the signs on the two sides of the river looked like they were written in different languages, Dad grinned: “They’re two different countries – Germany on our left and Luxembourg on our right! We’re navigating pretty much along the border!” Analytical note 1: In this period, geographical information was provided in the form of metal panels or ‘signs’ mounted on poles. Numerous examples can now be found in museums. Diary fragment 2: I couldn’t get over that – I mean, if we want to go abroad we have to get on a plane or a ferry, but here you can cross to another country without even having to show a passport. The joy of Schengen! Analytical note 2: Schengen was an early, and highly significant, stage in the dismantling of European border barriers. European union was long and complex, encountering frequent obstacles. Indeed many predicted that it would not survive the Covid pandemic. Diary fragment 3: After last night’s hotel (really scraping the bottom of the barrel!), I was prepared for the worst tonight, but I have my own room with its own bathroom and everything! In the lounge, I scraped together enough German to introduce myself to an Austrian group I met, and soon we were chatting away nineteen to the dozen. Dinner was hearty – fine by me as I had worked up a ravenous appetite. But soon I felt my eyelids drooping and excused myself. So here I am, writing by the light of my bedside lamp, looking forward to new adventures on the waterways of Europe tomorrow. Analytical note 3: For the unknown writer of this text, Schengen represented a way for holiday-makers to enjoy Europe’s rivers. Looking back on this tumultuous century, it is now clear that working in union was vital for European nations to face the challenges that lay ahead.
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Sample PowerPoint File St. Cloud Technical College This is a Sample Slide Here is an outline of bulleted points You can print out PPT files as handouts using the PRINT > PRINT WHAT > HANDOUTS option hello testing
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0 1 32 1562 2 25 1582 3 36 2587 4 25 3549 5 58 2468 96 34 2654 97 28 6525 98 32 3265 99 39 3265 100 29 6125 First Name Last Name Gender Country Age Date Id Dulce Abril Female United States 15/10/2017 Mara Hashimoto Great Britain 16/08/2016 Philip Gent Male France 21/05/2015 Kathleen Hanner Nereida Magwood Roma Lafollette Felisa Cail Demetria Abbey Jeromy Danz Rasheeda Alkire Hello Testing
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
const officeParser = require("../officeParser");
|
|
2
|
+
const fs = require("fs");
|
|
3
|
+
const supportedExtensions = require("../supportedExtensions");
|
|
4
|
+
|
|
5
|
+
// File names of test files and their text output content
|
|
6
|
+
// test file name style => test.<ext>
|
|
7
|
+
// test content output => test.<ext>.txt
|
|
8
|
+
|
|
9
|
+
/** List of all supported extensions with office Parser */
|
|
10
|
+
const supportedExtensionTests = [
|
|
11
|
+
{
|
|
12
|
+
ext: "docx",
|
|
13
|
+
testAvailable: true,
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
ext: "xlsx",
|
|
17
|
+
testAvailable: true,
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
ext: "pptx",
|
|
21
|
+
testAvailable: true,
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
ext: "odt",
|
|
25
|
+
testAvailable: true,
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
ext: "odp",
|
|
29
|
+
testAvailable: true,
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
ext: "ods",
|
|
33
|
+
testAvailable: true,
|
|
34
|
+
},
|
|
35
|
+
];
|
|
36
|
+
|
|
37
|
+
/** Local list of supported extensions in test file */
|
|
38
|
+
const localSupportedExtensionsList = supportedExtensionTests.map(test => test.ext);
|
|
39
|
+
|
|
40
|
+
/** Get filename for an extension */
|
|
41
|
+
function getFilename(ext, isContentFile = false) {
|
|
42
|
+
return `test/files/test.${ext}` + (isContentFile ? `.txt` : '');
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Run test for a passed extension */
|
|
46
|
+
function runTest(ext) {
|
|
47
|
+
return officeParser.parseOfficeAsync(getFilename(ext))
|
|
48
|
+
.then(text =>
|
|
49
|
+
fs.readFileSync(getFilename(ext, true), 'utf8') == text
|
|
50
|
+
? console.log(`[${ext}]=> Passed`)
|
|
51
|
+
: console.log(`[${ext}]=> Failed`)
|
|
52
|
+
)
|
|
53
|
+
.catch(error => console.log("ERROR: " + error))
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async function runAllTests() {
|
|
57
|
+
for (let i = 0; i < supportedExtensionTests.length; i++)
|
|
58
|
+
{
|
|
59
|
+
const test = supportedExtensionTests[i];
|
|
60
|
+
if (test.testAvailable)
|
|
61
|
+
await runTest(test.ext)
|
|
62
|
+
else
|
|
63
|
+
console.log(`[${test.ext}]=> Skipped`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Enable console output in case something fails
|
|
68
|
+
// officeParser.enableConsoleOutput();
|
|
69
|
+
|
|
70
|
+
// Run all test files with test content if no argument passed.
|
|
71
|
+
if (process.argv.length == 2)
|
|
72
|
+
{
|
|
73
|
+
// Test to check all items in local extension list are present in supportedExtensions.js file
|
|
74
|
+
localSupportedExtensionsList
|
|
75
|
+
.every(ext => supportedExtensions.includes(ext))
|
|
76
|
+
? console.log("All extensions in test files found in primary supportedExtensions.js file")
|
|
77
|
+
: console.warn("Extension in test files missing from primary supportedExtensions.js file");
|
|
78
|
+
|
|
79
|
+
// Test to check all items in supportedExtensions.js file are present in local extension list
|
|
80
|
+
supportedExtensions
|
|
81
|
+
.every(ext => localSupportedExtensionsList.includes(ext))
|
|
82
|
+
? console.log("All extensions in primary supportedExtensions.js file found in test file")
|
|
83
|
+
: console.warn("Extension in primary supportedExtensions.js file missing from test file");
|
|
84
|
+
|
|
85
|
+
runAllTests();
|
|
86
|
+
}
|
|
87
|
+
else if (process.argv.length == 3)
|
|
88
|
+
{
|
|
89
|
+
if (localSupportedExtensionsList.includes(process.argv[2]))
|
|
90
|
+
officeParser.parseOfficeAsync(getFilename(process.argv[2]))
|
|
91
|
+
.then(text => console.log(text))
|
|
92
|
+
.catch(error => console.log("ERROR: " + error))
|
|
93
|
+
else
|
|
94
|
+
console.error("The requested extension test is not currently available.");
|
|
95
|
+
}
|
|
96
|
+
else
|
|
97
|
+
console.error("Invalid arguments");
|
package/.vscode/settings.json
DELETED