OpenFile
Opens the document file which will be edited and saved afterwards.
Syntax
- Python
- C++
- COM
- Java
- .Net
- JS
def OpenFile(self, path: str, params: str | None = None) -> bool
int OpenFile(const wchar_t* sPath, const wchar_t* sParams);
HRESULT OpenFile([in] BSTR path, [in] BSTR params, [out, retval] VARIANT_BOOL* result);
boolean openFile(String path, String params);
bool OpenFile(String^ sPath, String^ sParams);
OpenFile(path, params)
Parameters
- Python
- C++
- COM
- Java
- .Net
- JS
| Name | Type | Description |
|---|---|---|
| path | str | The path to the file to be opened together with its name and extension. |
| params | str | None | The parameters needed for the correct file opening (most commonly, the encoding is used for the txt and csv file types or the delimiter for the csv files, for other file types this is just an empty string). The parameters are added in the form of XML tags, where m_nCsvTxtEncoding is used for the text encoding and m_nCsvDelimiter is used for the delimiter. You can find all the supported values for the encoding in this file. The supported values for the csv delimiters include: 0 - no delimiter; 1 - tab; 2 - semicolon; 3 - colon; 4 - comma; 5 - space. |
| Name | Type | Description |
|---|---|---|
| sPath | const wchar_t* | The path to the file to be opened together with its name and extension. |
| sParams | const wchar_t* | The parameters needed for the correct file opening (most commonly, the encoding is used for the txt and csv file types or the delimiter for the csv files, for other file types this is just an empty string). The parameters are added in the form of XML tags, where m_nCsvTxtEncoding is used for the text encoding and m_nCsvDelimiter is used for the delimiter. You can find all the supported values for the encoding in this file. The supported values for the csv delimiters include: 0 - no delimiter; 1 - tab; 2 - semicolon; 3 - colon; 4 - comma; 5 - space. |
| Name | Type | Description |
|---|---|---|
| path | BSTR | The path to the file to be opened together with its name and extension. |
| params | BSTR | The parameters for correct file opening. |
| result | VARIANT_BOOL* | Specifies if the operation is successful or not. |
| Name | Type | Description |
|---|---|---|
| path | String | The path to the file to be opened together with its name and extension. |
| params | String | The parameters needed for the correct file opening (most commonly, the encoding is used for the txt and csv file types or the delimiter for the csv files, for other file types this is just an empty string). The parameters are added in the form of XML tags, where m_nCsvTxtEncoding is used for the text encoding and m_nCsvDelimiter is used for the delimiter. You can find all the supported values for the encoding in this file. The supported values for the csv delimiters include: 0 - no delimiter; 1 - tab; 2 - semicolon; 3 - colon; 4 - comma; 5 - space. |
| Name | Type | Description |
|---|---|---|
| sPath | String^ | The path to the file to be opened together with its name and extension. |
| sParams | String^ | The parameters needed for the correct file opening (most commonly, the encoding is used for the txt and csv file types or the delimiter for the csv files, for other file types this is just an empty string). The parameters are added in the form of XML tags, where m_nCsvTxtEncoding is used for the text encoding and m_nCsvDelimiter is used for the delimiter. You can find all the supported values for the encoding in this file. The supported values for the csv delimiters include: 0 - no delimiter; 1 - tab; 2 - semicolon; 3 - colon; 4 - comma; 5 - space. |
| Name | Type | Description |
|---|---|---|
| path | String | The path to the file to be opened together with its name and extension. |
| params | String | Optional. The parameters for file opening (encoding for txt/csv, delimiter for csv). |
Opening PDF files
Starting from version 10.0, PDF files can be opened for editing. The editor is selected by the file contents:
- A PDF form created in ONLYOFFICE is opened in the document editor. Edit it with the Document API and the Form API.
- Any other PDF file is opened in the PDF editor. Edit it with the PDF API.
To open a password-protected PDF file, pass the password in the m_sPassword tag of the params parameter, for example, <m_sPassword>password</m_sPassword>.
Example
- Python
- C++
- COM
- Java
- .Net
- JS
import docbuilder
builder = docbuilder.CDocBuilder()
builder.OpenFile("document.csv", "<m_nCsvTxtEncoding>46</m_nCsvTxtEncoding><m_nCsvDelimiter>4</m_nCsvDelimiter>")
std::wstring sWorkDirectory = NSUtils::GetBuilderDirectory();
CDocBuilder::Initialize(sWorkDirectory.c_str());
CDocBuilder oBuilder;
oBuilder.OpenFile(L"document.csv", "<m_nCsvTxtEncoding>46</m_nCsvTxtEncoding><m_nCsvDelimiter>4</m_nCsvDelimiter>");
CDocBuilder::Dispose();
CoInitialize(NULL);
IONLYOFFICEDocBuilder* oBuilder = NULL;
CoCreateInstance(__uuidof(CONLYOFFICEDocBuilder), NULL, CLSCTX_INPROC_SERVER, __uuidof(IONLYOFFICEDocBuilder), (void**)&oBuilder);
VARIANT_BOOL b;
oBuilder->OpenFile(_bstr_t("document.csv"), _bstr_t("<m_nCsvTxtEncoding>46</m_nCsvTxtEncoding><m_nCsvDelimiter>4</m_nCsvDelimiter>"), &b);
oBuilder->Dispose();
CDocBuilder.initialize("");
CDocBuilder builder = new CDocBuilder();
builder.openFile("document.csv", "<m_nCsvTxtEncoding>46</m_nCsvTxtEncoding><m_nCsvDelimiter>4</m_nCsvDelimiter>");
CDocBuilder.dispose();
string workDirectory = "C:/Program Files/ONLYOFFICE/documentBuilder";
CDocBuilder.Initialize(workDirectory);
CDocBuilder oBuilder = new CDocBuilder();
oBuilder.OpenFile("document.csv", "<m_nCsvTxtEncoding>46</m_nCsvTxtEncoding><m_nCsvDelimiter>4</m_nCsvDelimiter>");
CDocBuilder.Destroy();
builder.OpenFile("document.csv", "<m_nCsvTxtEncoding>46</m_nCsvTxtEncoding><m_nCsvDelimiter>4</m_nCsvDelimiter>");
builder.SaveFile("xlsx", "result.xlsx");
builder.CloseFile();