I'm using Javascript API for Office to get ooxml of parts of the document using Binding.getDataAsync. The result is that I have ooxml text which represent part of the document:
Now what I want is to alter this XML for example to put a table around the contents or to show a comment then save it back using Binding.getDataAsync.
How can I use OpenOffice SDK to parse this xml to a document or a document part and do this processing?
I tried to use all the following:
var doc = new DocumentFormat.OpenXml.Wordprocessing.Document(ooxmlText);
//var part = new DocumentFormat.OpenXml.Wordprocessing.DocPart(ooxmlText);
//var parts = new DocumentFormat.OpenXml.Wordprocessing.DocParts(ooxmlText);
But I get back an error each time saying:
The XML has invalid content and cannot be constructed as an element.
Related
I have a web app that include blockly and I want to be able to save the structure user created on blockly on backend db.
I just want to know how to get the current workspace structure so I can post it to server to save it.
and then load it again when user login.
Thanks.
From Importing and exporting blocks:
If your application needs to save and store the user's blocks and restore them at a later visit, use this call for export to XML:
var xml = Blockly.Xml.workspaceToDom(workspace);
var xml_text = Blockly.Xml.domToText(xml);
This will produce a minimal (but ugly) string containing the XML for the user's blocks. If one wishes to obtain a more readable (but larger) string, use Blockly.Xml.domToPrettyText instead.
Restoring from an XML string to blocks is just as simple:
var xml = Blockly.Xml.textToDom(xml_text);
Blockly.Xml.domToWorkspace(xml, workspace);
When Kentico documents have images embedded in them, the image is inserted into the HTML as an <img> tag. I need to determine if this image is hosted by Kentico and if so, use the Kentico API to retrieve the database information for it.
So far I have parsed the File GUID out of the URL like this:
const string attachmentPrefix = "~/getattachment/";
if (imageElement.LinkAddress.StartsWith(attachmentPrefix))
{
var start = attachmentPrefix.Length;
var end = imageElement.LinkAddress.IndexOf("/", start);
var fileGuidString = imageElement.LinkAddress.Substring(start, end - start);
var fileGuid = new Guid(fileGuidString);
var info = AttachmentHistoryInfoProvider.GetInfoByGuid("-- what goes here --", fileGuid);
}
But I have not found any useful methods in the Kentico API that will retrieve information about the attachment from the GUID. The closest I found was AttachmentHistoryInfoProvider.GetInfoByGuid() but it takes an objectType parameter that I can't find any documentation for.
Does anyone know how to get information on attachments in Kentico 7 starting from a File GUID?
You mention that you're talking about images in the media library, but are trying to use the AttachmentHistoryInfoProvider in your code sample. I think it depends on what you are referring to when you say 'documents have media library images embedded in them'; in what way are you embedding them? Perhaps using the Editable image web part for example.
If you are using files from the media library, you should try using MediaFileInfoProvider.GetMediaFileInfo(Guid, string) which takes the Guid of the file and the site code name. This will return you a MediaFileInfo class. You can find it in the CMS.DataEngine assembly in Kentico 7. For a file from a media library, I'd expect to see a URL like /SampleSite/media/cats/nohandskitten.aspx to be rendered.
If you're not using images from the media library, but are inserting directly into content, then yes - this is an attachment. Rather than using AttachmentHistoryInfoProvider, you should use AttachmentInfoProvider. Calling AttachmentInfoProvider.GetAttachmentInfo(Guid, string) with the Guid of the file and the site code name will return the AttachmentInfoObject. I believe the AttachmentHistoryInfoProvider will only return things to you if you have object versioning enabled. For a file from an attachment, I'd expect to see a URL like /getattachment/75408145-0995-45dc-943a-d27296a45327/nohandskitten.jpg.aspx.
These InfoProviders do fundamentally different things, so long as you know what type of information you're looking for, you should be able to choose the correct one
If you don't have it already, the API reference for Kentico 7 may be helpful: https://devnet.kentico.com/docs/7_0/kenticocms_api.zip
I have a JSON document having some properties including attachment(abc.txt).
How to save attachments in couchbase using Node.JS?
Take a look at the Couchbase Node.JS SDK
You have two choices in how to store the attachment:
Inline with the document. If the attachment is small and/or easily embedded into JSON (the attachment is valid JSON itself) then you can simply add a element to your JSON document containing the attachment body, for example:
{attachment_name: "abc.txt",
attachment_body: "The quick brown fox jumps over the lazy dog\n"
...
}
As a separate document, referenced from the first. If the document is large / you don't want to serialize it inline, then create a field which just refers to the key of the actual attachment:
{attachment_name: "abc.txt",
attachment_ref: "attachment::document1_attachment1"
...
}
Then you'd have a second document named attachment::document1_attachment which was the actual attachment document.
On SalesForce ,
I've got a word document as an attachment of a custom object, i can get it as blob by selecting the body of the attachment with a SOQL query :
Attachment att = [ SELECT Body FROM Attachment WHERE PARENTID = '**' and ContentType='application/msword'] ;
Blob b = att.body ;
I tried to use the b.toString() function to have the content, but it didn't work.So is there any other way to convert the blob into a string that represent the text written in my word document.
thanks
Document bodies are saved as Blobs and are base64Encoded. Please use the EncodingUtil class and bas64Encode/base64Decode methods to achieve the desired results.
Documentation: http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_restful_encodingUtil.htm
What exactly are you trying to achieve with this?
If you are trying to display the doc. content and let the user edit/save it. This is not possible unless ActiveX controls are used which is another different level.
Please post the code if any coding help is required!
The b.toString() method should return a string of the blob. But keep in mind that it isn't translating the proprietary format of the word document into plain text. It's still going to be a string with some ugliness because it represents the word document format and not the text you would see when viewing from word.
XPages application uses "template" documents containing two fields binded to RichText editor and file upload/download controls.
Regular documents initially link to template document, with one datasource for common fields (title, category, readers/authors...) of current document, and second datasource shows read only RT+attachments from template.
When user decides to alter RT/attachments, he unlinks document from template - by copying RT+attachments from template to current document.
The problem: standard Java snippet for RT copy (and attachments too) is:
session.setConvertMime(true);
RichTextItem rti = (RichTextItem)docTemplate.getFirstItem("Body");
rti.copyItemToDocument(docCurrent, "Body");
rti = (RichTextItem)docTemplate.getFirstItem("Files"); <====
rti.copyItemToDocument(docCurrent, "Files");
docCurrent.save(); //saves in RT format, next save via XPage converts to MIME
This always works for Body field (although it alters formatting a bit), but it rarely works for attachments.
Resave of template document in Notes client converts RT from MIME to native RT format and code works without problem.
Not working means:
exception java.lang.ClassCastException: lotus.domino.local.Item incompatible with lotus.domino.RichTextItem at line with arrow.
missing Files field (Body is created correctly tho)
For some attachments code seem to work (text file), for bigger or binary it fails (23k .doc, 3M .pdf).
LotusScript alternative of above code called as agent does not help either.
Datasource property computeWithForm is not used by purpose.
Question: what is proper technique for copying MIME attachment(s) between documents?
The quickest way would be using Document.copyAllItems(Document doc, boolean replace) and than removing what is unnecessary.