openxml can't open docx file throught sharepoint rest - sharepoint

I'm using the sharepoint rest api to get the contents of a docx file like so
_api/web/getfolderbyserverrelativeurl('openxmlJsPoc')/files('TemplateDocument.docx')/$value
I get the contents of the file, But I'm having trouble reading it with the openxml javascript api.
this is a sample the return data that I get:
PK ! î¦o´• )  Í[Content_Types].xml ¢É(  ¼•MKÃ#†ï‚ÿ!ìUš­
"ÒÔƒG¬àuÝLÚÅýbgÚÚï$Ú(Z[iª—#²;ïûì»3dpþâl6ƒ„&øBæ}‘ס4~\ˆ‡ÑuïTdHÊ—Ê…X ŠóáþÞ´ˆ€W{,Ä„(žI‰zNa"x^©BrŠø5eTúYAõû'ROà©Gµ†.¡RSKÙÕ~#IQdok¯B¨­ÑŠ˜TÎ|ùÅ¥÷îse³'&âc¹Ò¡^ùÙà½î–£I¦„ìN%ºQŽ1ä<¤R–AOŸ!_/³‚3T•ÑÐÖ×j1
ˆœ¹³y»â”ñKþ9ˆÙ<;³42-ˆ;Û};úRy#BÅ}1ROvÏÐJo„˜ÃÓýŸEñI|7Ë]
%Gç, ¿Ê÷c„DÚùYÕ­·i‹‹XÎk]ýKÇfòþ¢ùÝuaë)RpÎJCàšÜ:‡ÞŠÖz›Co·0tŸûVtk†ãÿÎá£ùšKÙ‘ýŠ>”Ínø
ÿÿ PK ! ™U~ á  ó_rels/.rels ¢ï(  ¬’ÏJÃ#Æï‚ï°Ì½™´Šˆ4éE„ÞDâ»Ó$˜ýÃîTÛ·w-ˆjÒƒÇùæ›ß|ìzs°ƒzç˜zï*X%(vÚ›Þµ¼6O‹{PIȼã
ŽœS__­_x ÉC©ëCRÙÅ¥
:‘ð€˜tÇ–Rá»ÜÙùhIò3¶H¿Q˸*Ë;Œ¿= yª­© nÍ
¨æòæyo¿Ûõš½Þ[vrfòAØ6‹3[”>_£Š-KÆëç\NH!ð<Ñêr¢¿¯EËB†„PûÈÓ<_Š) åå#ó?é|øh0GtÊvŠæö?iô>‰·3ñœ4ßH8ú˜õ' ÿÿ PK ! v¥S¬" Û Ú word/_rels/document.xml.rels ¢Ö (  ¬”ËjÃ0E÷…þƒÑ¾–í´i)‘³)…l[ºUäñƒêa¤I[ÿ}E ±Cƒ’…6‚¡{W#­Ö¿J&ß]o4#yš‘´0u¯[F>ª×
which I'm positive its correct because when i save this as a docx file it opens correctly.
tried using
openXml.OpenXmlPackage(result);
// and
doc = new openXml.OpenXmlPackage();
doc.openFromArrayBuffer
but I keep getting errors
please help!

the problem was with the JZIP.js that comes packaged with the sdk.
A better approac is to save the template as a Word xml file and then download it through ajax and open it.
worked for me

Related

Js-Report not display other language when deploy on lambda

I have use js-report to generate pdf with thai language
all of my process is
1.get csv file from s3
2.read data and convert csv to object
3.send object to jsreport
i already done all process in local and it's work fine .
but when i deploy this project on lambda (we can attach js report to lambda. more details in this url : jsreport-aws-lambda )
but when i deploy and test, it's not displaying thai language(and i think maybe other language too.)
at first i think it's becode encoding ('base64') i try to change it's to utf-8 but the file is corrupted.
I already set meta content of html file to
enter code here
but's still not working
what can i do to solved this, please help me.
Thanks.

Uploading documents to Alfresco CMIS using Python

I am trying to upload documents to a Alfresco CMIS site using Python code
from cmislib.model import CmisClient
file_to_upload = open(file_full_path, 'r')
doc_in_Alfresco = archive_folder_2.createDocument(file_name, \
contentFile=file_to_upload)
Have taken the example from this help document - https://chemistry.apache.org/python/docs/examples.html
i have .txt, .rtf, . pdf, .docx documents etc.
Except for txt documents, rest of the upload is failing and the common error is
LookupError: 'base64' is not a text encoding; use codecs.encode() to handle arbitrary codecs
The error will differ in codec name depending on the file extension.
With limited documentation help, can someone hint what can be the possible solution. I am using cmislib in Python 3 in MacOS and the code in run in Jupyter Notebook.
Any hints will be highly appreciated.
Thanks
It worked for me with the following changes in place
file_to_upload.read()
file_data = base64.b64encode(content_file.read())
doc_in_Alfresco = archive_folder_2.createDocument(file_name, \
contentFile=file_to_upload)

I'm trying to get an excel sheet downloaded using python requests module and getting junk output

I'm trying to download an excel file which is uploaded on a Sharepoint 2013 site.
My code is as follows:
import requests
url='https://<sharepoint_site>/<document_name>.xlsx?Web=0'
author = HttpNtlmAuth('<username>','<passsword>')
response=requests.get(url,auth=author,verify=False)
print(response.status_code)
print(response.content)
This gives me a long output which is something like:
x00docProps/core.xmlPK\x01\x02-\x00\x14\x00\x06\x00\x08\x00\x00\x00!\x00\x7f\x8bC\xc3\xc1\x00\x00\x00"\x01\x00\x00\x13\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb8\xb9\x01\x00customXml/item1.xmlPK\x05\x06\x00\x00\x00\x00\x1a\x00\x1a\x00\x12\x07\x00\x00\xd2\xba\x01\x00\x00\x00'
I did something like this before for another site and I got xml as output which was acceptable for me but I'm not sure how to handle this data.
Any ideas to process this to be like xlsx or xml?
Or maybe to download the xlsx another way?(I tried doing it through the wget library and the excel seems to get corrupted)
Any ideas would be really helpful.
Regards,
Karan
Its too late but i got similar issue... thought it might help someone else.
try writing the output to a file or apply some encoding while printing.
writing to a file:
file=open("./temp.xls", 'wb')
file.write(response.content)
file.close()
or
file=open("./temp.xls", 'wb')
file.write(response.text)
file.close()
printing with encoding
print ( resp.text.encode("utf-8") )
or
print ( resp.content.encode("utf-8") )
!Make appropriate imports.
!try 'w' or 'wb' for file write.
Hope this helps.
It seems that the file is encrypted and request can't handle this.
Maybe the web service provides an API for downloading and secure decoding.

How to extract the zipped xls file from the email attachment?

I have a module which is supposed to extract the email attachment and place it at a specific location. The code creates the POP3 Client to fetch the mail and has been using EMAIL::MIME::Attachment::Stripper module to extract the attachment as below.
my $mail=$pop->HeadAndBody($i);
my $parsed = Email::MIME->new($mail);
my $stripper = Email::MIME::Attachment::Stripper->new($parsed);
my #attachments = $stripper->attachments;
foreach my $a(#attachments)
{
next if $a->{content_type} !~ /octet-stream/i;
my $f = new IO::File "C:/MAIL_PARSING_DATA/" . "<filename>.<file-extension>", "w" or die "Can not create file!";
print $f $a->{payload};
goto EXITPOINT;
}
The code is working fine for the standard files identified by the Perl module, like spreadsheet etc. But not for the specific mail which has a zipped Excel file as an attachment. While extracting the file the identified content_type by the Perl script for this file is application/octet-stream. While extracting the file using the above-mentioned code the file seems to be broken because:
The file is not getting opened through WinZip, WinRAR or 7-Zip.
File size for the file extracted through this script is slightly different than the same file extracted using Outlook.
Kindly provide some input on the issue.
The problem is here
next if $a->{content_type} !~ /octet-stream/i;
zip have content type as application/zip
#NeoNox, Thanks for the response. But the perl system identifies the file as octet-stream only, not with application/zip.
Anyways, I could find the solution.
I could resolve the problem by writing the file in the binary mode(mentioning explicitely as below:
binmode $fh;
Here the file is being writting in the binary mode So I don't get the output as the broken file.
I am finding the same issue.
XLSX files are not seen as attachments.
I am using IMAP.
It will download the email body, any jpgs or pngs etc but does not find the attached xlsx even when in an email that has attachments that are downloaded.

SharePoint and Office Open XML interaction question

I've been frustrated by this for the entire weekend, plus a day or two, so any help would be significantly appreciated.
I'm trying to write a program that can programmatically go into a SharePoint 2007 doc library, open a file, change the contents of the file, then put the file back. I've gotten all but the last part of this down. The reason Office Open XML is involved is that that's how I'm opening the document and modifying it - through the Office Open XML SDK. My question is: How do I get it from the document back into the library?
The problem as I see it is that there's no save function on the WordprocessingDocument object itself. This prevents me from saving it into the SPFile's SaveBinary function.
You should use stream's to write back the changed OOXML into the SPFile.
I hope this example helps!
Stream fs = mySPFile.OpenBinaryStream();
using (WordprocessingDocument ooxmlDoc = WordprocessingDocument.Open(fs, true))
{
MainDocumentPart mainPart = wordDoc.MainDocumentPart;
XmlDocument xmlMainDocument = new XmlDocument();
xmlMainDocument.Load(mainPart.GetStream());
// change the contents of the ooxmlDoc / xmlMainDocument
Stream stream = mainPart.GetStream(FileMode.Open, FileAccess.ReadWrite);
xmlMainDocument.Save(stream);
// the stream should not be longer than the DocumentPart
stream.SetLength(stream.Position);
}
mySPFile.SaveBinary(fs);
fs.Dispose();
Yesterday I saw a webcast with Andrew Connell where he opened a doc from a doc library, added a watermark and saved the file again. It sure sounds like you should have a look at that webcast:
https://msevents.microsoft.com/CUI/WebCastRegistrationConfirmation.aspx?culture=en-US&RegistrationID=1299758384&Validate=false
btw I found that all 10 of the web casts in that serie were very good.

Resources