CreateFile
Creates a new file. The type of the file which will be created needs to be set.
Syntax
- Python
- C++
- COM
- Java
- .Net
- JS
def CreateFile(self, type: int | str) -> bool
bool CreateFile(int nExtension);
HRESULT CreateFile([in] BSTR type, [out, retval] VARIANT_BOOL* result);
boolean createFile(int type);
boolean createFile(String type);
bool CreateFile(int nType);
CreateFile(type)
Parameters
- Python
- C++
- COM
- Java
- .Net
- JS
| Name | Type | Description |
|---|---|---|
| type | int | str | The file type as a hexadecimal integer (OFFICESTUDIO_FILE_XXX values) or a string (docx, xlsx, pptx, pdf, form). |
| Name | Type | Description |
|---|---|---|
| nExtension | int | The type of the file to be created set as a hexadecimal integer (see OFFICESTUDIO_FILE_XXX values). |
| Name | Type | Description |
|---|---|---|
| type | BSTR | The file type (see Supported formats). |
| result | VARIANT_BOOL* | Specifies if the operation of creating a file is successful or not. |
| Name | Type | Description |
|---|---|---|
| type | int | String | The file type as a hexadecimal integer (OFFICESTUDIO_FILE_XXX values) or a string (docx, xlsx, pptx, pdf, form). |
| Name | Type | Description |
|---|---|---|
| nType | int | The type of the file to be created set as a hexadecimal integer (see OFFICESTUDIO_FILE_XXX values). |
| Name | Type | Description |
|---|---|---|
| type | String | The file type (see Supported formats). |
note
The pdf file type creates the same document as docx. To create a PDF form, pass the form file type to the CreateFile and SaveFile methods. The form content is edited with the Document API and the Form API. To edit an existing PDF file with the PDF API, open it with the OpenFile method.
Example
- Python
- C++
- COM
- Java
- .Net
- JS
import os
import docbuilder
builder = docbuilder.CDocBuilder()
builder.CreateFile("docx")
dstPath = os.getcwd() + "/result.docx"
builder.SaveFile("docx", dstPath)
builder.CloseFile()
std::wstring sWorkDirectory = NSUtils::GetBuilderDirectory();
CDocBuilder::Initialize(sWorkDirectory.c_str());
CDocBuilder oBuilder;
oBuilder.CreateFile(OFFICESTUDIO_FILE_DOCUMENT_DOCX);
CDocBuilder::Dispose();
CoInitialize(NULL);
IONLYOFFICEDocBuilder* oBuilder = NULL;
CoCreateInstance(__uuidof(CONLYOFFICEDocBuilder), NULL, CLSCTX_INPROC_SERVER, __uuidof(IONLYOFFICEDocBuilder), (void**)&oBuilder);
VARIANT_BOOL b;
oBuilder->Initialize();
oBuilder->CreateFile(_bstr_t("docx"), &b);
oBuilder->Dispose();
CDocBuilder.initialize("");
CDocBuilder builder = new CDocBuilder();
builder.createFile(FileTypes.Document.DOCX);
CDocBuilder.dispose();
string workDirectory = "C:/Program Files/ONLYOFFICE/documentBuilder";
CDocBuilder.Initialize(workDirectory);
CDocBuilder oBuilder = new CDocBuilder();
var doctype = (int)OfficeFileTypes.Document.DOCX;
oBuilder.CreateFile(doctype);
CDocBuilder.Destroy();
builder.CreateFile("docx");
builder.SaveFile("docx", "result.docx");
builder.CloseFile();