官术网_书友最值得收藏!

Exporting a DataTable

We may need to save data that is collected during a run session. For example, a comparison of the current result with previous results might be required. Alternatively, we might wish to update the expected results. In such scenarios, we can save the data to an external Excel sheet for later use.

How to do it...

To save the DataTable in its current state before the run session ends, we will use the DataTable.Export method, which takes the path and name of an Excel file as an argument. There are two options to save the data table:

  • Using a hardcoded filename:
    DataTable.Export(Environment("TestDir") & "\MyDynamicallySavedExcel.xls")
  • Using a variable filename:
    DataTable.Export(Environment("TestDir") & "\" & strFileName & ".xls")

How it works...

The preceding statement saves the current contents of the DataTable (all worksheets) to a new Excel file (if not existent, otherwise it is overwritten). The statement Environment("TestDir") returns a string with the path of the current test to which a string with the name of the file we wish to create is concatenated (TestDir is one of the built-in Environment variables covered in detail later in this chapter).

There's more...

To export just a single worksheet (in our example, the global sheet) for an action, use the DataTable.ExportSheet method, as follows:

call DataTable.ExportSheet(Environment("TestDir") & "\MyDynamicallySavedSheet1.xls", "Global")

Here, the first parameter is the Excel filename and the second is the source datasheet. The target datasheet will take the same name as the source.

主站蜘蛛池模板: 新郑市| 进贤县| 洛扎县| 济源市| 乌拉特前旗| 延寿县| 鄂托克前旗| 皋兰县| 太白县| 荃湾区| 滦南县| 庆阳市| 石柱| 敦煌市| 周至县| 上栗县| 东兰县| 彰化市| 张掖市| 松江区| 金门县| 常州市| 佛山市| 沙河市| 古田县| 桐庐县| 齐河县| 大姚县| 南开区| 惠安县| 武冈市| 兰溪市| 灯塔市| 土默特右旗| 天水市| 泗洪县| 青海省| 宁都县| 贺兰县| 台州市| 巴塘县|