I am trying to implement Custom XML parts feature in Office js.
While creating custom XML part in Excel, I am getting a GeneralException
while adding the XML part in workbook.
I am fetching data from excel having 5000 rows and 4 columns.
I am encoding the data using Base64 encoding and storing the data in a XML tag in the following format -
My encoded data.
Are there any size limitation while adding a custom XML part in the workbook ?Is there any specific behind this error?
Example:
Excel.run(function (ctx) {
var xmlObj = "<data>My encoded data.</data>";
var xmlPart = ctx.workbook.customXmlParts.add(xmlObj);
return ctx.sync();
});
Thanks for bringing this issue to our attention! I was able to repro the behavior on a blank workbook against excel.exe. It is due to a bug that we will try to fix in the nearest future. Sorry for the inconvenience. Please stay tuned for Excel updates.
There is no size limitation as such. I'd recommend the following:
Try with smaller number of rows.
Make sure the final XML is valid (you could use online validation tool to make sure there are no special characters, etc. that's giving the error). Ideally the API should tell you if the XML is invalid... but worth double-checking.
Is this happening only when you encode? Try using just regular string concatenation for the sake of testing.
Please let us know where it fails in above tests.
Related
I am using a REST api to get XML data from a database and am trying to display it in an html format using xslt. Unfortunately the xml data comes back with a few namespaces that are not defined. I can get the style sheet to work just fine on a local copy of the data if I strip the namespaces or define them. Striping the name spaces feels like a hack and no the correct way to do this.
this is essentially an example of the data I get back:
<root>
<entity:Entity ns1:atrib="foo">
<g:Value>foo1</g:value>
<g:Name>fooName</g:Name>
</entity:Entity>
xmlhttprequest methods in JS to get this information and XSLTProcessor to transform it then add it into a . It's not displaying the transformed information and i'm 100% positive it's the namespaces that is causing the issue.
I've googled everything I can think of with no luck. Road blocks like this are almost always due to me missing something fundamental.
XSLT will only operate on XML that is well-formed, and it requires all namespaces to be declared. If you want to process this data you should ideally fix it at source; if you can't do that you need to repair it before processing.
There are some XML parsers that allow you to process non-namespace-aware XML, and you could use such a parser as the basis of your repair tool, but this is such an unusual requirement that I'll have to leave you to research how to do that yourself.
Forgive the lack of code but I'm working in a production environment and it's a lot. I can provide more specific examples if needed but I will explain the basic situation here.
I'm using a library called PdfMake (which is excellent btw, great for making pdf's in JS if you need that) to make a dynamic PDF on the fly.
Now I need to get the PDF into an S3 bucket, but our stack currently relies on ColdFusion. Luckily, PdfMake has a handy method to convert the pdf data to Base64 and ColdFusion has a handy function to convert Base64 to binary.
So I sent the base64 to my server, convert it to binary, make a new coldfusion pdf and read it like this (fileData is a base64 encoded string)
public function upload_pdf(string fileName, any fileData){
var myPdf = new pdf();
var binary = ToBinary(arguments.fileData);
myPdf.read( source=binary, name="fileSource");
}
For some reason this action is failing. I usually get an error that says "The Document has no catalog of type dictionary", which is very cryptic and brings up no helpful results when I search it. Sometimes, without changing anything, I get an error that reads "the rebuild document still has no trailer". From googling it seems trailers are something specific to do with PDFs.
Intuitively I would think that this would work, since base64 and binary are versatile types of encoding. However I'm at a loss as to how to even begin to fix or diagnose this. I will probably begin looking for another solution altogether but I am curious to learn more about what is happening here so if anyone has any ideas I am down for some discussion.
FOR ANY CURIOUS READERS I HAVE SOLVED THIS PROBLEM, HERE IS THE WORKING CODE:
public function upload_pdf(string fileName, string fileData){
var myPdf = new pdf();
var binary = decodeBinary(Replace(arguments.fileData, " ", "+", "ALL"));
myPdf.setSource(binary);
}
Is it possible to be able to upload an excel document with varying ranges of data, and have that data dynamically displayed in a basic form of chart(bar, pie, etc.) on our company website.
After doing some research I figured the only two possible ways to maybe do something like this is to use a very complicated macro in VBA or a Javascript parser to read the data and display it then. The data that will eventually go in here will have sensitive information so I cannot use google charts or anything like that.
This problem has to be divided into two parts.
One -part is to gather and process the information needed to display the chart.
Second - This is the easiest, a way to display a chart in HTML. For this, you can use www.c3js.org javascript library to display the chart in HTML.
Regarding part one, it depends in which technology is built your website.
For example, If it is in php, you will need to find a library in php, which can read and parse excel files.
Then you have to create a service in your website, where the data is going to be provided. For example,
www.yourcompany.com/provideChartData.php
You can format the response as json format.
Once you have solved that, you only have to call the service from your page, and the data will be dynamically displayed. You can call it using jquery library for javascript ($.post("www.yourcompany.com/provideChartData.php",function (data) { code to display chart ....}))
There is no real easy way to do this that I have found. I have had to manually parse these things in the past but there are some libraries out there for node that might help you.
https://www.npmjs.com/package/node-xlsx
You can also export form excel as CSV. When you do this, me sure to set the custom separator to something other than ',' and you should be fine to import it into a large array and get the data/charts you need.
https://github.com/wdavidw/node-csv
Hope that helps.
I'm relatively new to javascript but I want to get some data from a csv file that is saved online and gets updated each hour.
The data should be displayed on a table later on but I have some problems with saving it to an array. The csv file is comma seperated, has 9 columns, over 6000 rows and is a long string of text, so no linebreaks. The first row contains usernames and each username with special characters is conclosed with quotation marks.
I've tried several codes over the past few days, but none worked. Can I parse a online CSV file into an array at all? Is there an alternative like with SQL or saving the file to my server?
Remember: The file gets updated each hour..
NOTE: There are not really problems with the codes I've found, all of these were tested by others and seemed to work. But only for local files, not actual URLs!
You can use this https://code.google.com/p/jquery-csv/ plugin and it is possible to convert multi-line csv into 2D-array using $.csv.toArrays(csv) or to an object using $.csv.toObjects(csv). Check this post or this one for more info
$.ajax({
url: "urlto/filename.csv",
success: function (data) {
var arr = $.csvtoArray(data);
_oncomplete(arr);
},
dataType: "text",
});
_oncomplete: function (arr) {
//Your array here
}
You can have a look at papaparse for a solid and full-featured CSV parsing library.
setInterval javascript function lets you update the data every hour, in case you decide to develop this part on the client.
Is there an alternative like with SQL or saving the file to my server?
Yes there are alternatives, the right architecture depends on your use case. How many visitors will go to your web page and view the results, how critical your application is, how reliable the data source is, etc. If you're not sure about these you should talk to a web developer with more experience around these questions.
You may want to parse the CSV file every hour on the server and store a copy of the data there, to serve to your visitors. This way, if the upstream data source is unavailable, you still have a copy of the data from the past.
P.S.:
I've tried several codes over the past few days, but none worked
stackOverflow is about this: getting help about specific problems in your code, rather than asking general questions (answer to those can be found easily using a search engine).
I am trying to use docx.js to generate a Word document but I can't seem to get it to work.
I copied the raw code into the Google Chrome console after amending line 247 to fix a "'textAlign' undefined error"
if (inNode.style && inNode.style.textAlign){..}
Which makes the function convertContent available. The result of which is an Object e.g.
JSON.stringify( convertContent($('<p>Word!</p>)[0]) )
Results in -
"{"string":
"<w:body>
<w:p>
<w:r>
<w:t xml:space=\"preserve\">Word!</w:t>
</w:r>
</w:p>
</w:body>"
,"charSpaceCount":5
,"charCount":5,
"pCount":1}"
I copied
<w:body>
<w:p>
<w:r>
<w:t xml:space="preserve">Word!</w:t>
</w:r>
</w:p>
</w:body>
into Notepad++ and saved it as a file with an extension of 'docx' but when I open it in MS Word but it says 'cannot be opened because there is a problem with the contents'.
Am I missing some attribute or XML tags or something?
You can generate a Docx Document from a template using docxtemplater (library I have created).
It can replace tags by their values (like a template engine), and also replace images in a paid version.
Here is a demo of the templating engine: https://docxtemplater.com/demo/
This code can't work on a JSFiddle because of the ajaxCalls to local files (everything that is in the blankfolder), or you should enter all files in ByteArray format and use the jsFiddle echo API: http://doc.jsfiddle.net/use/echo.html
I know this is an older question and you already have an answer, but I struggled getting this to work for a day, so I thought I'd share my results.
Like you, I had to fix the textAlign bug by changing the line to this:
if (inNode.style && inNode.style.textAlign)
Also, it didn't handle HTML comments. So, I had to add the following line above the check for a "#text" node in the for loop:
if (inNodeChild.nodeName === '#comment') continue;
To create the docx was tricky since there is absolutely no documentation on this thing as of yet. But looking through the code, I see that it is expecting the HTML to be in a File object. For my purposes, I wanted to use the HTML I rendered, not some HTML file the user has to select to upload. So I had to trick it by making my own object with the same property that it was looking for and pass it in. To save it to the client, I use FileSaver.js, which requires a blob. I included this function that converts base64 into a blob. So my code to implement it is this:
var result = docx({ DOM: $('#myDiv')[0] });
var blob = b64toBlob(result.base64, "application/vnd.openxmlformats-officedocument.wordprocessingml.document");
saveAs(blob, "test.docx");
In the end, this would work for simple Word documents, but isn't nearly sophisticated for anything more. I couldn't get any of my styles to render and I didn't even attempt to get images working. I've since abandoned this approach and am now researching DocxgenJS or some server-side solution.
You may find this link useful,
http://evidenceprime.github.io/html-docx-js/
An online demo here:
http://evidenceprime.github.io/html-docx-js/test/sample.html
You are doing the correct thing codewise, but your file is not a valid docx file. If you look through the docx() function in docx.js, you will see that a docx file is actually a zip containing several xml files.
I am using Open Xml SDK for JavaScript.
http://ericwhite.com/blog/open-xml-sdk-for-javascript/
Basically, on web server, I have a empty docx file as new template.
when user in browser click new docx file, I will retrieve the empty docx file as template, convert it to BASE64 and return it as Ajax response.
in client scripts, you convert the BASE64 string to byte array and using openxmlsdk.js to load the byte array as an javascript OpenXmlPackage object.
once you have the package loaded, you can use regular OpenXmlPart to create a real document. (inserting image, creating table/row ).
the last step is stream it out to end user as a document. this part is security related. in my code I send it back to webserver and gets saved temporarily. and prepare a http response to notify end user to download it.
Check the URL above, there are useful samples of doing this in JavaScript.