open(path, timeout=6000) - данная функция открывает файл
Функция на вход принимает параметры:
- path – путь к файлу.
- timeout – время открытия файла.
После отработки функция возвращает результат своей работы в робот (тип возвращаемого значения boolean):
- true – файл успешно открыт
- false – не удалось открыть файл
Пример использования open (PHP):
<?php $xhe_host = "127.0.0.1:7018"; // подключим объект для управления эмулятором, если еще не подключен if (!isset($path)) $path="../../../Templates/init.php"; require($path); // начало echo "<hr><font color=blue>excelfile->".basename (__FILE__)."</font><hr>"; // путь к файлу $path="test\\test.xlsx"; // 1 echo("\n1. Откроем : "); echo($excelfile->open($path)); // 2 echo("\n2. Выведем все ячейки : "); for ($i=1;$i<=$excelfile->get_rows_count($path,0);$i++) { for ($j=1;$j<=$excelfile->get_cols_count($path,0);$j++) echo $excelfile->get_cell($path,0,$i,$j)."|"; echo "\n"; } // 3 echo("\n3. Скопируем ячейки на 2 лист c новыми цветами: "); for ($i=1;$i<=$excelfile->get_rows_count($path,0);$i++) { for ($j=1;$j<=$excelfile->get_cols_count($path,0);$j++) { echo $excelfile->set_cell($path,1,$i,$j,$excelfile->get_cell($path,0,$i,$j))." "; $excelfile->set_cell_background_color($path,1,$i,$j,"FF0000FF"); $excelfile->set_cell_color($path,1,$i,$j,"FFFFFF00"); } echo "\n"; } // 4 echo("\n4. Сохраним : "); echo($excelfile->save($path)); // 5 echo("\n5. Закроем : "); echo($excelfile->close($path)); // посмотрим $app->shell_execute("open","test\\test.xlsx"); // конец echo "<hr><br>"; // Quit $app->quit(); ?>
Пример использования open (C#):
#region using using System; using System.Diagnostics; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Threading; using XHE; using XHE.XHE_DOM; using XHE.XHE_System; using XHE.XHE_Window; using XHE.XHE_Web; #endregion class Program:XHEScript { static void Main(string[] args) { // init XHE server="127.0.0.1:7015"; InitXHE(); // начало echo("<hr><font color=blue>excelfile.get_sheets_count</font><hr>"); // путь к файлу string path="test\\test.xlsx"; // 1 echo("\n1. Откроем : "); echo(excelfile.open(path)); // 2 echo("\n2. Выведем все ячейки : "); for (int i=1;i<=excelfile.get_rows_count(path,0);i++) { for (int j=1;j<=excelfile.get_cols_count(path,0);j++) echo(excelfile.get_cell(path,0,i,j.ToString())+"|"); echo("\n"); } // 3 echo("\n3. Скопируем ячейки на 2 лист c новыми цветами: "); for (int i=1;i<=excelfile.get_rows_count(path,0);i++) { for (int j=1;j<=excelfile.get_cols_count(path,0);j++) { echo(excelfile.set_cell(path,1,i,j.ToString(),excelfile.get_cell(path,0,i,j.ToString()))+" "); excelfile.set_cell_background_color(path,1,i,j.ToString(),"FF0000FF"); excelfile.set_cell_color(path,1,i,j.ToString(),"FFFFFF00"); } echo("\n"); } // 4 echo("\n4. Сохраним : "); echo(excelfile.save(path)); // 5 echo("\n5. Закроем : "); echo(excelfile.close(path)); // посмотрим app.shell_execute("open","test\\test.xlsx"); // конец echo("<hr><br>"); app.quit(); } }
Пример использования open (Python):
# Additional paths import sys sys.path.insert(0, '../../../Templates PY/') xhe_host = "127.0.0.1:7015" from xweb_human_emulator import * # начало echo("<hr><font color=blue>excelfile.get_sheets_count</font><hr>") # путь к файлу path="test\\test.xlsx"; # 1 echo("\n1. Откроем : "); echo(excelfile.open(path)); # 2 echo("\n2. Выведем все ячейки : "); for i in range(1, excelfile.get_rows_count(path,0)): for j in range(1, excelfile.get_cols_count(path,0)): echo(excelfile.get_cell(path,0,i,j)+"|") echo("\n") # 3 echo("\n3. Скопируем ячейки на 2 лист c новыми цветами: "); for i in range(1, excelfile.get_rows_count(path,0)): for j in range(1, excelfile.get_cols_count(path,0)): echo(excelfile.set_cell(path,1,i,j,excelfile.get_cell(path,0,i,j))," ") excelfile.set_cell_background_color(path,1,i,j,"FF0000FF") excelfile.set_cell_color(path,1,i,j,"FFFFFF00") echo("\n") # 4 echo("\n4. Сохраним : "); echo(excelfile.save(path)); # 5 echo("\n5. Закроем : ") echo(excelfile.close(path)) # посмотрим app.shell_execute("open","test\\test.xlsx") # конец echo("<hr><br>") # Quit app.quit()
Пример использования open (JS):
xhe_host="127.0.0.1:7015"; echo=require("../../../Templates JS/init.js"); // начало echo("<hr><font color=blue>excelfile.get_sheets_count</font><hr>"); // путь к файлу path="test\\test.xlsx"; // 1 echo("\n1. Откроем : "); echo(excelfile.open(path)); // 2 echo("\n2. Выведем все ячейки : "); for (i=1;i<=excelfile.get_rows_count(path,0);i++) { for (j=1;j<=excelfile.get_cols_count(path,0);j++) echo(excelfile.get_cell(path,0,i,j)+"|"); echo("\n"); } // 3 echo("\n3. Скопируем ячейки на 2 лист c новыми цветами: "); for (i=1;i<=excelfile.get_rows_count(path,0);i++) { for (j=1;j<=excelfile.get_cols_count(path,0);j++) { echo(excelfile.set_cell(path,1,i,j,excelfile.get_cell(path,0,i,j))+" "); excelfile.set_cell_background_color(path,1,i,j,"FF0000FF"); excelfile.set_cell_color(path,1,i,j,"FFFFFF00"); } echo("\n"); } // 4 echo("\n4. Сохраним : "); echo(excelfile.save(path)); // 5 echo("\n5. Закроем : "); echo(excelfile.close(path)); // посмотрим app.shell_execute("open","test\\test.xlsx"); // конец echo("<hr><br>"); // Quit app.quit();