ExecuteCommand
Executes the command which will be used to create the document file (text document, spreadsheet, presentation, form document, PDF). See the Text document API, Spreadsheet API, Presentation API, or Form API sections for more information which commands are available for various document types.
note
For JS, call the API methods directly instead.
Syntax
- Python
- C++
- COM
- Java
- .Net
def ExecuteCommand(self, command: str, retValue: CDocBuilderValue | None = None) -> bool
bool ExecuteCommand(const wchar_t* sCommand, CDocBuilderValue* oRetValue = 0);
HRESULT ExecuteCommand([in] BSTR command, [out, retval] VARIANT_BOOL* result);
boolean executeCommand(String command, CDocBuilderValue retValue);
bool ExecuteCommand(String^ sCommand, CDocBuilderValue^% oRetValue);
Parameters
- Python
- C++
- COM
- Java
- .Net
| Name | Type | Default | Description |
|---|---|---|---|
| command | str | The command in the form of JavaScript code which will be used to create the document file (in Python, the escape character must be used when the command contains quotation symbols). | |
| retValue | CDocBuilderValue | None | None | The command return value. |
| Name | Type | Default | Description |
|---|---|---|---|
| sCommand | const wchar_t* | The command which will be used to create the document file (in C++, the escape character must be used when the command contains quotation symbols). | |
| oRetValue | CDocBuilderValue* | 0 | The command return value. |
| Name | Type | Description |
|---|---|---|
| command | BSTR | The command which will be used to create the document file (in COM, the escape character must be used when the command contains quotation symbols). |
| result | VARIANT_BOOL* | Specifies if the operation of executing a command is successful or not. |
| Name | Type | Default | Description |
|---|---|---|---|
| command | String | The command in the form of JavaScript code which will be used to create the document file (in Java, the escape character must be used when the command contains quotation symbols). | |
| retValue | CDocBuilderValue | null | The command return value. |
| Name | Type | Default | Description |
|---|---|---|---|
| sCommand | String^ | The command in the form of JavaScript code which will be used to create the document file (in .Net, the escape character must be used when the command contains quotation symbols). | |
| oRetValue | CDocBuilderValue^% | null | The command return value. |
Example
- Python
- C++
- COM
- Java
- .Net
import os
import docbuilder
builder = docbuilder.CDocBuilder()
builder.CreateFile("docx")
builder.ExecuteCommand("var oDocument = Api.GetDocument();var oParagraph = oDocument.GetElement(0);oParagraph.AddText('Hello from Python!');")
dstPath = os.getcwd() + "/result.docx"
builder.SaveFile("docx", dstPath)
builder.CloseFile()
std::wstring sWorkDirectory = NSUtils::GetBuilderDirectory();
CDocBuilder::Initialize(sWorkDirectory.c_str());
CDocBuilder oBuilder;
oBuilder.ExecuteCommand(L"oParagraph.AddText(\"Hello, world!\");");
CDocBuilder::Dispose();
CoInitialize(NULL);
IONLYOFFICEDocBuilder* oBuilder = NULL;
IONLYOFFICEDocBuilderValue* oRun = NULL;
VARIANT_BOOL b;
oBuilder->Initialize();
oBuilder->Execute(L"oParagraph.AddText(\"Hello, world!\");", &oRun);
oBuilder->ExecuteCommand(L"oParagraph.SetSpacingAfter(1000, false);", &b);
oBuilder->Dispose();
CDocBuilder.initialize("");
CDocBuilder builder = new CDocBuilder();
builder.executeCommand("oParagraph.AddText(\"Hello from Java!\");");
CDocBuilder.dispose();
string workDirectory = "C:/Program Files/ONLYOFFICE/documentBuilder";
CDocBuilder.Initialize(workDirectory);
CDocBuilder oBuilder = new CDocBuilder();
oBuilder.ExecuteCommand("oParagraph.AddText(\"Hello from .Net!\");");
CDocBuilder.Destroy();