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

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.

主站蜘蛛池模板: 唐海县| 遂溪县| 洪湖市| 当雄县| 轮台县| 西林县| 湖州市| 聂拉木县| 道孚县| 永兴县| 宁强县| 乐至县| 宁城县| 陇西县| 武安市| 台山市| 云安县| 宁化县| 肇庆市| 中宁县| 陇西县| 平利县| 遂宁市| 山东省| 嘉祥县| 达尔| 彰化县| 江都市| 巫山县| 古蔺县| 宁夏| 威海市| 娱乐| 黑龙江省| 正蓝旗| 马龙县| 驻马店市| 故城县| 闽清县| 依兰县| 瑞丽市|