How to set properties like title, author, subject for a file created with docx library for .net ?
docx
The DocX project that you provided appears to be able to easily access the metadata properties that you are referring to and can do so quite easily by using the CoreProperties property as seen below :
// Load your Document
var wordFile = Novacode.DocX.Load(#"your-docx-file-path");
// Access Metadata properties
var props = wordFile.CoreProperties;
The issue here is that this collection of properties is read only, so you won't be able to easily change them. However, you may be able to take a look at what the values look like and attempt to add one manually :
So if you wanted to update the title property (clearly named dc:title), you would simply need to add a new Core Property (via the AddCoreProperty() method) that matched that same name and then save the file to persist the changes :
// Load your Document
var wordFile = DocX.Load(#"your-docx-file-path");
// Update Metadata
wordFile.AddCoreProperty("dc:title", "Example Title");
wordFile.Save();
After doing this, you should be able to re-open the file and see that your changes reflected :
As you can see the dc:title property is now set to "Example Title" as per the example code above.
Related
In my docx file we have some readonly fields but, While i'm updating docx file using docx4j library that read only fields become editable.
XML Block
In document we have some section and readonly block for guide the user and below that section we have added block for enter value.
Dependency
compile "org.docx4j:docx4j-JAXB-ReferenceImpl:8.3.4"
In Word, Review > Restrict Editing > Editing Restrictions > Filling in Forms
results in the following in the Document Settings part, word/settings.xml:
<w:documentProtection w:edit="forms" w:enforcement="1"/>
Check this value before and after manipulation with docx4j.
If it is changing, then something in your code is changing it.
Basically you want something like:
DocumentSettingsPart documentSettingsPart = getPkg().getMainDocumentPart().getDocumentSettingsPart();
documentSettingsPart.protectRestrictEditing(STDocProtect.FORMS, null, null);
See further https://github.com/plutext/docx4j/blob/VERSION_11_4_7/docx4j-core/src/main/java/org/docx4j/openpackaging/parts/WordprocessingML/DocumentSettingsPart.java#L311
How can I replace the current document in a bokeh server app?
I have a previous document saved as a json_string. If I do
set_curdoc(Document.from_json_string(json_string))
this seems to properly change curdoc(), however the new document is not displayed in the browser.
I found a workaround, other places suggest to update the children of an existing layout instead of updating the whole curdoc().
I did that but I had to expand a bit to do that from a document saved in a json string.
I had to switch the document attribute of all the models from the imported document to curdoc() instead (otherwise it complains that the models belong to another document)
assuming that the document I import and the current document both have only one root:
new_doc = Document.from_json_string(json_string)
new_grid_models = collect_models(new_doc.roots[0])
for elem in new_grid_models:
try:
elem.document = curdoc()
except AttributeError:
elem._document = curdoc()
new_children = new_doc.roots[0].children
del new_doc
grid.children = new_children
After that the python callbacks need to be re-affected to the appropriate imported models.
I put up an example app here:
save_and_load app on Bitbucket
You can just clear the current document and then add a new one:
Put the whole code to create your document (bokeh app) into a function create_curdoc(). At the very end of this function you have curdoc().add_root(layout).
Call the function create_curdoc() once to create and display the document
Clear the current document with curdoc().clear()
Call the function create_curdoc() with updated data again (or another function that creates a document) to create and display the new document.
If you dont clear before calling the function again the new document will just be added at the bottom of the old one.
You could, for example, trigger the update by a button callback inside your current document.
The button setup might look like this:
def replace():
curdoc().clear()
create_curdoc()
replace_button = Button(
label="Replace Document",
button_type= "danger")
replace_button.on_click(replace)
I recently pull a project from GitHub that included a compile-soy task in its build.xml. The task uses SoyToJsSrcCompiler.jar to compile a couple of soy files into javascript. The project included the target directory so I could see that the compiled files contain code like this:
jive.fbldr.soy.attachments = function(opt_data, opt_sb) {
var output = opt_sb || new soy.StringBuilder();
output.append('<div class="fbldr-attachments"><div class="fbldr-attach-head"><p>Use the following form to upload file attachments and, optionally, include a variable to reference the uploaded file in the form\'s HTML source.</p><p>Multiple files may be attached, but only one at a time. Click "Finished" when all files have been attached.</p></div><div class="fbldr-attach-field"><label>Link to HTML Variable (optional) : </label></div><div class="fbldr-attach-field"><select id="fbldr-attach-link"><option value="" selected="selected">Select HTML variable...</option>');
var optionList34 = opt_data.variables;
var optionListLen34 = optionList34.length;
When I run the same task without any code changes, the resulting compiled keeps replacing opt_sb with opt_ignored and stripped out all references to soy.StringBuilder. I ran "java -jar lib/SoyToJsSrcCompiler.jar --outputPathFormat target/soy2/fbldr.soy templates/fbldr.soy" by hand instead of using the build.xml. I get the same result.
jive.fbldr.soy.attachments = function(opt_data, opt_ignored) {
var output = '<div class="fbldr-attachments"><div class="fbldr-attach-head"><p>Use the following form to upload file attachments and, optionally, include a variable to reference the uploaded file in the form\'s HTML source.</p><p>Multiple files may be attached, but only one at a time. Click "Finished" when all files have been attached.</p></div><div class="fbldr-attach-field"><label>Link to HTML Variable (optional) : </label></div><div class="fbldr-attach-field"><select id="fbldr-attach-link"><option value="" selected="selected">Select HTML variable...</option>';
var optionList4 = opt_data.variables;
var optionListLen4 = optionList4.length;
From all the Closure Templates documentation I've read, it is expected the output will use StringBuilder. I cannot figure out why my call keeps generating output that ignores the StringBuilder. Would someone happen to know what could cause this?
StringBuilder was appropriate for Internet Explorer 7 and earlier browsers. For modern browsers simple string concatenation is more efficient and Closure Templates was changed to make that mode the default mode (as an added bonus, the code is smaller). It sounds like the documentation has not been updated to reflect this change.
If for compatibility reasons your require StringBuilder you can set this option on the command-line using --codeStyle stringbuilder
I am using Devexpress XtraReport suite in my application which works fine for dynamic reporting requirement except one customization as below:
User is given report preview using ReportPrintTool with dynamic data.
Now, when user tries to export print preview as Image file with 'ExportMode=Different Files' output file names are generated based on report name(i.e. reportName+pageIndex.png) which i need to define based on some dynamic value or say based on a column value provided to report as data source.
Can anybody please guide me how can I achieve this customization?
Reference from: XtraReport default file name in SaveDialog box
Try to set the XtraReport.ExportOptions.PrintPreview.DefaultFileName option (PrintPreviewOptions.DefaultFileName Property).
PrintControl.PrintingSystem.ExportOptions.PrintPreview.DefaultFileName = "column value that you provide"
To know that how to use it, Follow the below reference links:
default name of report during saving - Here some file name standard related issue also descripbed
How modify predefined file name on exporting report
XtraReports - Custom filename when exporting via the reports toolbar
I have written a GUI extension which adds an additional tab to many of the Item views in the SDL Tridion CME (e.g. Component, Page and Schema etc.). I have also written some JavaScript which loads that tab directly if when the view is loaded with a tab name is specified in the URL.
The result is that if a page is loaded with the tab name added as follows:
http://localhost/WebUI/item.aspx?tcm=64#id=tcm:1-48-64&tab=InfoTab
Rather than the default of
http://localhost/WebUI/item.aspx?tcm=64#id=tcm:1-48-64
The Info Tab will be loaded on top, instead of the General Tab. This is performed with the following code snippet and works very well:
$evt.addEventHandler($display, "start", onDisplayStarted);
// This callback is called when any view has finished loading
function onDisplayStarted() {
$evt.removeEventHandler($display, "start", onDisplayStarted);
var tabname = $url.getHashParam("tab");
if (tabname != '') {
var tabControl = $controls.getControl($("#MasterTabControl"), "Tridion.Controls.TabControl");
tabControl.selectItem(tabname);
}
}
Now I would like to make a context menu item to open items and link to the tabs using my new functionality. My first thought was to construct the Item URL myself and simply open a new window in my execute method. So I looked at the default functionality in the standard Open.prototype_execute() functionality of the GUI. This is stored in the navigation.js file of the CME, and is performed by the Tridion.Cme.Commands.Open.prototype._execute method. The code is a lot more complicated than I had anticipated as it deals with shared items, and permissions etc.
Rather than just copying all of this code to my own function, I was wondering if there is a way to elegantly extend the existing Open.prototype_execute() function and append my “&tab=MyTab” to the $cme.Popups.OPEN_ITEM_OPTIONS.URL constant for my own functions.
Any advice would be greatly appreciated.
At the end the Open command uses $config.getEditorUrl(item_type) to get the url for the item view (item_type - $const.ItemType.COMPONENT, etc). There are no extension points for this part of the functionality, but you could always try to overwrite it on your own risk.