Tables in MultiCAD.NET. Part 3: Saving and loading table from an external file


The previous post about tables in MultiCAD.NET described how to create, modify and format tables with different data types and mentioned using table templates. In this post we will talk about templates and look more closely at the API that allows you to save a table to an external file as a template and then load it to the drawing to create type tables. Also the post will describe the table data exchange process between a MultiCAD.NET application and Microsoft Excel.

Example table

Let’s assume that the example table describes different types of mounting profiles (C-studs, U-channels etc.) and contains the following data: name, code, thickness, function.


Example table

We showed how to create and format tables in the previous post. Here, we’ll discuss how to save this table to an external file so that we can use it later as a template.

Saving table as a template

To save a table to a separate file, the McTable.SaveToFile() method is used. The table can be saved to a file of one of the following formats:

  • .dat files,
  • tabbed text (.txt),
  • comma-separated text,
  • XML,
  • Microsoft Excel (.xls),
  • (.ods).

The table to be saved can be picked from the drawing. The following command allows user to pick a table and save it to a file of the available formats:

Loading table from a file

To load a table from an external file, use the McTable.LoadFromFile() method. As well as for SaveToFile(), the file name can be specified explicitly or chosen from the dialog. The following file formats are supported for loading:

  • table .tbl, .dat files,
  • text (.txt, .csv, .xml),
  • Microsoft Access(.mdb, .accdb),
  • Microsoft Excel (.xls, .xlsx),
  • (.ods),
  • StarOffice (.sxc)

The following command adds a table from the user selected file to the drawing:

Now the saved table can be used as a template for adding type tables to the drawing:


Type tables based on the template table

Exchanging data with Excel

In addition to saving tables to files, MultiCAD.NET has the ability to quickly exchange data with Microsoft Excel sheets.

When the ExportToExcel() method is called, the table data is copied to a newly created and opened Excel book, keeping the cells format the same.
The following command lets the user select a table in the drawing and export it to an Excel sheet:

Also MultiCAD.NET supports importing table data from Excel. To import a selected cell range from the opened Excel sheet, use the ImportFromExcel() method:

This post concludes our review of the basic features of the tables API in MultiCAD.NET. This was definitely not the entire list of the abilities provided by the API, so if you have any questions or suggestions regarding this functionality please feel free to write comments. The tables feature list is currently being enhanced and we’ll be happy to get suggestions for more subjects to discuss in future posts.

Leave a Reply