Spreadsheet document in table of values ​​1s 8.2

In order to upload the tabular part (of a document, reference book, processing, etc.) to table of values method must be used Unload(). When you use it it will be created table of values with the same set of columns (same data types) and with the same data as in tabular part. It should be noted that this table is in no way related to tabular part and changing the data in it will not lead to changing the data in it; in fact, it is a copy of it, but with slightly different properties and methods.

Also, if you have a table with the same set of columns as in the tabular part, then the data from the value table can be loaded into the tabular part. For this purpose the method is used Download(<Таблица>) , tabular part. This may be required if the data to be loaded is obtained by request. And instead of going through the query result in a loop, you can simply load it into the table part.

Unload tabular part 1c. Example

Download the tabular part. Example

Let us assume that in the variable Object contains a document object that has a tabular part Services. And in the variable Request, contains a query collecting data for the tabular part.

A value table is a specific universal object designed to store data in a tabular representation. The key difference between a table and application objects is the lack of binding to physical database tables. The value table exists only in RAM, which, on the one hand, provides unique opportunities, and on the other, imposes certain restrictions. Nevertheless, the possibilities of interaction with the table are comparable to interaction with objects that actually exist in the database.

Historically, the table of values ​​in 1C has a dual purpose, being a virtual analogue of existing tables, but at the same time it is also a control element. With the transition to managed application Most of this functionality has been deprecated, but today it can also be a user interface element, but with a number of significant limitations.

Structure of a value table as an object

The properties of a value table are determined by combinations of two predefined collections: its columns and rows.

Table of values ​​Columns

A column of a table of values ​​is its defining property. It is the set of table columns that determines its structure. The columns correspond to the fields of physical tables or those familiar from user interface columns of a tabular section or document journal. A column can have an internal name, a value type, and a title that is displayed when working interactively with the table.

Since columns are a collection of objects, you can add, delete, and edit columns.

Value table row

From a software interface perspective, strings are a separate collection embedded in a table of values. They are analogous to records in physical tables, that is, rows familiar to the user in a tabular section or document journal. Each individual row is an object with a set of named properties, the names of which correspond to the names of the table columns.

Thus, interacting with a string is very similar to interacting with other objects. You can read and write its properties, including using the predefined function “FillPropertyValues()”. Since rows are the main collection of the value table, the Clear() method is used to delete all rows in the table.

Create table of values

There are many ways to get a table of values ​​ready for use. Let's look at some of them. Each example will be provided as code listings with comments.

Creating a table using the constructor

The main method that allows you to create exactly the table that the developer needs is, unfortunately, the most labor-intensive, since it requires manually specifying all the necessary table properties.

DemoTable = New ValueTable; // First of all, initialize the technical specifications // Next, we determine the necessary parameters for new columns and add them to the collection // Creating the "Nomenclature" column Name = "Nomenclature"; ValueType = New TypeDescription("DirectoryLink.Nomenclature"); Title = "Nomenclature (product)"; DemoTable.Columns.Add(Name, ValueType, Header); // Creating the "Quantity" column Name = "Quantity"; ValueType = New TypeDescription("Number"); DemoTable.Columns.Add(Name, ValueType); // As a result of these manipulations, we created an empty table with typed columns // If you need to use more precise typing primitive types, then you should use the extended syntax of the “Description of Types” constructor

Creating a table by copying

If you have a reference with a suitable structure and/or composition on hand, you can copy or download the reference table of values. If the reference table is another table, then you need to use the “Copy reference tables” method. If you are dealing with a tabular part or a set of register records, you must use the “Unload table of values” method. If you only need the structure, you can use the “Copy Columns” method.

// Option with copying all lines from the technical specification standard but preserving only the two specified columns. Columns of the Standard = "Nomenclature, Quantity"; DemoTable = TableEtalon.Copy(, ColumnsEtalon); // Option with copying pre-selected rows from the technical specification standard, while preserving the two specified columns. Rows of the Standard = SelectIntoArrayThe Rows We Need From the Table of the Standard(); ColumnsStandard = "Nomenclature, Quantity"; DemoTable = TableEtalon.Copy(RowsEtalon, ColumnsEtalon); // Option for copying rows from the technical specification standard using the specified filter, preserving one column “Nomenclature” // All rows where the value in the Quantity column is equal to 0 will be selected, only the Nomenclature column Row Selection = New Structure("Quantity" will appear in the resulting table , 0); ColumnsStandard = "Nomenclature"; DemoTable = TableEtalon.Copy(RowsEtalon, ColumnsEtalon); // Option with a complete copy of the table and subsequent deletion of one row with the quantity field value equal to zero and deletion of the entire “Quantity” column. Row Selection = New Structure("Quantity", 0); ColumnsStandard = "Nomenclature"; DemoTable = TableEtalon.Copy(RowsEtalon, ColumnsEtalon); TableRow = DemoTable.Find(0, "Quantity"); DemoTable.Delete(TableRow); DemoTable.Columns.Delete("Quantity"); // Similar options and their modifications can be applied to tabular parts and sets of register records

Creating a table with a query

If a template of the table you need exists in the database, then you can use a query to quick creation tables with the required structure.

// Example with creation empty table based on the model of the structure of the accumulation register // It is not difficult to guess that in this way you can get a completed table Request = New Request("SELECT FIRST 0 * From Accumulation Register. Products in Warehouse"); RequestResult = Request.Execute(); DemoTable = Query Result.Unload(); // An example of creating an empty table using explicitly specified types and field names Query = New Query; Query.Text = "SELECT TOP 0 | Value(Directory.Nomenclature.EmptyLink) AS Nomenclature, | EXPRESS(0 AS NUMBER(15, 3)) AS Quantity"; RequestResult = Request.Execute(); DemoTable = Query Result.Unload(); // IMPORTANT! Do not forget that the types of column values ​​obtained from a request always contain the Null type // Thus, the technical specification created by the request always has composite types speakers

Conclusion

In this short article, we looked at the basic properties and practical techniques for creating a table of values, sufficient for understanding and starting to use. The value table object itself is so multifaceted that detailed description its capabilities requires writing a separate article on techniques and methods of work.

The method is based on the use of an object Report Builder is an object that allows, based on the specified query text or data source, as well as settings, to obtain the result and display it in a spreadsheet document or chart.

Description of the method

1. We obtain the area of ​​cells of the spreadsheet document that needs to be placed in the table of values. Getting the area must be specified in such a way that it includes a row of column headers (see Figure 1), a feature of the operation of the Report Builder object.

CellArea = TabDocument.Area(1, 1, LastRow, LastColumn);


2. Based on the cell area of ​​the spreadsheet document, we create a description of the data source.

DataSource = NewDataSourceDescription(CellArea);

3. Create a Report Builder object, specify the data source instead of the query text, and build the report.



Result of reading data from the source after calling the method Run() is in the property Result. This property contains an object of type RequestResult; an object of the same type is returned when the request is executed.

4. Unload the result into the table of values ​​(see Figure 2) by calling the Unload() method of an object of the Query Result type.

ValueTable = ReportBuilder.Result.Unload();

Of the obvious disadvantages, the column values ​​are of string type. Also, the Report Builder object is available only on the server, so you will have to transfer the spreadsheet document from the client to the server.

Final code

Function ConvertTabularDocumentToValueTable(TabDocument)
LastRow = TabDocument.TableHeight;
LastColumn = TabDocument.TableWidth;
CellArea = TabDocument.Area(1, 1, LastRow, LastColumn);
// Create a description of the data source based on the cell area of ​​the spreadsheet document.
DataSource = NewDataSourceDescription(CellArea);
// Create an object for intelligent reporting,
// specify the data source and build the report.
ReportBuilder = New ReportBuilder;
ReportBuilder.DataSource = DataSource;
ReportBuilder.Run();
// The result is uploaded to the value table.
ValueTable = ReportBuilder.Result.Unload();
Returning TabValues
EndFunction

Processing with implementation this method can be downloaded

Connection