Skip to main content
A newer version of this page is available. .

How to: Insert Data

  • 3 minutes to read

The following example describes how to add data to a document in the Snap Report API.

The Snap document has a basic tabular structure. When data is added at runtime, data fields are placed to the automatically created table cells. To add new data to the document in the API, you need to insert data fields to the table cells as well. To complete this task, follow the steps below:

  1. Load the document template using the RichEditDocumentServer.LoadDocumentTemplate method.
  2. Call the ISnapFieldOwner.CreateSnList method to create a new Snap list or retrieve one of the existing lists by calling the ISnapFieldOwner.FindListByName method.
  3. Convert the document fields to Snap Fields. To do that, call the ISnapFieldOwner.ParseField method. Note that if this step is skipped, you will not be able to modify the document.
  4. Enable modification of the list by calling the SnapEntity.BeginUpdate method.
  5. Access the row template through the SnapList.RowTemplate property.
  6. To add a new cell in the row, call the TableCellCollection.InsertAfter or TableCellCollection.InsertBefore method, depending on where you want to add the cell.
  7. To retrieve one of the existing document table cells, access the cell collection using the TableRow.Cells property and get the desired cell by its index.
  8. Insert the required data field. To do that, use the ISnapFieldOwner.CreateSnText method. Use the position within the desired table cell as a method parameter. The TableCell.ContentRange property provides access to the cell range.
  9. If necessary, create a cell in the list header. To do that, access the list header through the SnapList.ListHeader property, retrieve the header’s table row and use the SubDocument.InsertText method to insert the desired content to the cell. To create a new table cell, use the TableCellCollection.InsertAfter or TableCellCollection.InsertBefore method.
  10. Update the list’s fields by calling the FieldCollection.Update method. Updating the fields activates the modifications you have created.
Dim list As SnapList = server.Document.FindListByName("Data Source 11")

' Add a header to the Snap list.                                                                   
Dim listHeader As SnapDocument = list.ListHeader
Dim listHeaderTable As Table = listHeader.Tables(0)
Dim listHeaderCells As TableCellCollection = listHeaderTable.FirstRow.Cells
listHeader.InsertText(listHeaderCells.InsertAfter(2).ContentRange.End, "Quantity per Unit")

' Add data to the row template:
Dim listRow As SnapDocument = list.RowTemplate
Dim listRowTable As Table = listRow.Tables(0)
Dim listRowCells As TableCellCollection = listRowTable.FirstRow.Cells
listRow.CreateSnText(listRowCells.InsertAfter(2).ContentRange.End, "QuantityPerUnit")