Ziv-Barber / officegen

Standalone Office Open XML files (Microsoft Office 2007 and later) generator for Word (docx), PowerPoint (pptx) and Excell (xlsx) in javascript. The output is a stream.
MIT License
2.65k stars 471 forks source link

Unable to load large URL links into word #326

Closed rohitchandalurivt closed 5 years ago

rohitchandalurivt commented 5 years ago

Environment

  1. node -v: v10.16.0
  2. npm -v: 6.9.0
  3. npm ls officegen: officegen@0.6.2
  4. Operating system: Mac OS 10.14.6
  5. Microsoft Office version: Version 16.27
  6. Problem with Powerpoint, Excel or Word document: Word document

Steps to Reproduce

pObj.addText( '8' ,{ link:'https://github.com/Telemedicine1/issues?q=is:issue+created:2019-05-12..2019-06-24+is:closed', font_size: 13, color: '#3D87F5'});

is not providing the link in the doc if the link is small it is providing the link given.

Expected Behavior

The word doc should contain the link given

Actual Behavior

The word doc is providing the element as link but the link is empty.


An example code:

const officegen = require('officegen')

const fs = require('fs') let docx = officegen('docx') // Officegen calling this function after finishing to generate the docx document: docx.on('finalize', function(written) { console.log( 'Finish to create a Microsoft Word document.' ) })

const link = 'https://github.com/Telemedicine1/issues?utf8=%E2%9C%93&q=is:issue+created:2019-05-12..2019-06-24';

let pObj = docx.createP(); pObj.addText( 'Report',{ bold: true, font_size: 20, color: 'black' }); pObj.addLineBreak (); pObj.addLineBreak (); pObj.addText( 'SUMMARY',{ link:'https://github.com/', bold: true, font_size: 14, color: 'black' }); pObj.addLineBreak (); pObj.addLineBreak (); pObj.addText( '1) A total of ',{ font_size: 13, color: 'black' }); pObj.addText( '21',{ link: link, font_size: 13, color: 'blue'}); pObj.addText( ' new issues opened last week out which ', { font_size: 13, color: 'black' }); pObj.addText( '8' ,{ link:'https://github.com/Telemedicine1/issues?q=is:issue+created:2019-05-12..2019-06-24+is:closed', font_size: 13, color: '#3D87F5'}); pObj.addText( ' were closed and ',{ font_size: 13, color: 'black' }); pObj.addText( '13' ,{ link:'https://github.com/Telemedicine1/issues?q=is:issue+created:2019-05-12..2019-06-24+is:open', font_size: 13, color: '#3D87F5'}); pObj.addText( ' are still open.',{ font_size: 13, color: 'black' }); pObj.addLineBreak();
pObj.addText( '2) A total of ',{ font_size: 13, color: 'black' }); pObj.addText( '16' ,{ link:'https://github.com/Telemedicine1/issues?utf8=%E2%9C%93&q=is:issue+closed:2019-05-12..2019-06-24+is:closed+', font_size: 13, color: '#3D87F5'}); pObj.addText( ' issues were closed (including bug bash).',{ font_size: 13, color: 'black' });

let out = fs.createWriteStream('example.docx')

docx.generate(out)

Ziv-Barber commented 5 years ago
pObj.addText( 'Link to Google' ,{ link:'https://www.google.com/', font_size: 13, color: '#3D87F5'});

Working for me.

The first parameter to addText is the text itself, or in this case the caption of the link.

Please let me know if you need more features because the next version dedicated to docx improvements and features.

rohitchandalurivt commented 5 years ago

Can you try with large link "https://github.com/Telemedicine1/issues?q=is:issue+created:2019-05-12..2019-06-24+is:closed"

and once done if you open the file and try to see the hyperlink of the text the hyper link is empty

rohitchandalurivt commented 5 years ago

The code i used

const officegen = require('officegen')

const fs = require('fs') let docx = officegen('docx') // Officegen calling this function after finishing to generate the docx document: docx.on('finalize', function(written) { console.log( 'Finish to create a Microsoft Word document.' ) })

const link = 'https://github.com/Telemedicine1/issues?utf8=%E2%9C%93&q=is:issue+created:2019-05-12..2019-06-24';

let pObj = docx.createP() pObj.addText('Even add ') pObj.addText('external link', { link: link }) pObj.addText('!');

let out = fs.createWriteStream('example.docx') docx.generate(out)

Ziv-Barber commented 5 years ago

I think that it's neither the link length nor special characters inside it. First try your link normally in the browser. In your case I got 404 code. I think it's permission problem. I tried long link with public access and it worked just fine.

Ziv-Barber commented 5 years ago

Did it solve your problem @rohitchandalurivt ?