How to set up smartphones and PCs. Informational portal
  • home
  • Reviews
  • 1c fill out a spreadsheet document from the table of values.

1c fill out a spreadsheet document from the table of values.

In order to unload the tabular section (document, reference book, processing, etc.) into value table you need to use the method Unload ()... When used, it will create value table 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 has nothing to do with tabular part and changing the data in it will not change 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 section, then the data of the table of values ​​can be loaded into the tabular section. For this, the method is applied Download(<Таблица>) , tabular section. This may be required if the data for loading is received by a request. And instead of looping through the query result, you can simply load it into the tabular section.

Unload tabular section 1c. Example

Load the tabular section. Example

Suppose that in the variable An object contains a document object that has a tabular section Services... And in the variable Inquiry, contains a request that collects data for the tabular section.

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 get the result and display it in a spreadsheet document or diagram.

Method description

1. Get the area of ​​cells of the spreadsheet document, which you want to place in the table of values. Obtaining an area should be set in such a way that it would include a row of column headings (see Figure 1), a feature of the ReportBuilder object.

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


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

DataSource = NewDataSourceDescription (CellScope);

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



The result of reading data from the source after calling the method Execute () is in the property Result... This property contains an object of the QueryResult type; an object of the same type is returned when the query is executed.

4. Let's unload the result into the table of values ​​(see Figure 2) by calling the Unload () method of the RequestResult object.

ValuesTable = ReportBuilder.Result.Upload ();

Of the obvious disadvantages, the values ​​of the columns are of the string type. Also, the ReportBuilder object is available only on the server, you will have to drive the spreadsheet document from the client to the server.

Final program code

Function ConvertTableDocumentToTableValues ​​(TabDocument)
LastRow = TabDocument.Table Height;
LastColumn = TabDocument.TableWidth;
CellScope = TabDocument.Area (1, 1, LastRow, LastColumn);
// Create a description of the data source based on the cell area of ​​the spreadsheet document.
DataSource = NewDataSourceDescription (CellScope);
// Create an object for intelligent construction of reports,
// specify the data source and build the report.
ReportBuilder = NewReportBuilder;
Report Builder.DataSource = DataSource;
Report Builder.Run ();
// Upload the result to the table of values.
ValuesTable = ReportBuilder.Result.Upload ();
Returning TabValues
EndFunction

Processing with the implementation of this method can be downloaded

A value table is a specific generic object for storing data in a table view. The key difference between tables and application objects is that they are not bound to physical database tables. The table of values ​​exists only in RAM, which, on the one hand, provides unique opportunities, and on the other hand, imposes certain restrictions. However, the ability to interact with a table is comparable to interacting 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 move to a managed application, most of this functionality has been deprecated, but it can now also be a user interface element, but with a number of significant limitations.

The structure of the table of values ​​as an object

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

Table of values ​​Columns

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

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

Values ​​table row

From a programming interface point of view, strings are a separate collection embedded in a table of values. They are analogous to the records of physical tables, that is, the rows of the tabular section or the document journal that are familiar to the user. Each row taken separately 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 table of values, the "Clear ()" method is used to delete all rows in the table.

Create a table of values

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

Creating a table by the designer

The main method that allows you to create just such a table that the developer needs is, unfortunately, the most time consuming, since it requires manually specifying all the necessary table properties.

DemoTable = NewValuesTable; // First of all, we initialize the TOR // Next, we define the necessary parameters for the new columns and add them to the collection // Create the "Nomenclature" column Name = "Nomenclature"; ValueType = NewDescription of Types ("ReferenceLink.Nomenclature"); Title = "Nomenclature (product)"; DemoTable.Columns.Add (Name, ValueType, Title); // Create a column "Quantity" Name = "Quantity"; ValueType = NewTypeDescription ("Number"); DemoTable.Columns.Add (Name, ValueType); // As a result of these manipulations, we have created an empty table with typed columns // If you need to use more precise typing of 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 at hand, you can copy or download the reference table of values. If the reference is another table, then it is necessary to apply the "Copy reference tables" method. If you are dealing with a tabular section or a set of register records, you must use the "Unload Table of Values" method. If you only need a structure, then you can use the "CopyColumns" method.

// Option with copying all lines from the technical standard, but keeping only the two specified columns. Columns of the Standard = "Nomenclature, Quantity"; DemoTable = TableDefault.Copy (, ColumnDefault); // Option with copying preselected rows from the TZ-template, keeping the two specified columns. ColumnsStandard = "Nomenclature, Quantity"; DemoTable = TableDefault.Copy (RowsDefault, ColumnDefault); // Option with copying rows from the TZ-standard by the specified filter, keeping one column “Nomenclature” // All rows will be selected where the value in the Quantity column is 0, only the Nomenclature column will be included in the resulting table. , 0); ColumnStandard = "Nomenclature"; DemoTable = TableDefault.Copy (RowsDefault, ColumnDefault); // Option with full copying of the table and subsequent deletion of one row with the value of the quantity field equal to zero and deletion of the whole column “Quantity” Selection of Lines = New Structure ("Quantity", 0); ColumnStandard = "Nomenclature"; DemoTable = TableDefault.Copy (RowsDefault, ColumnDefault); TableRow = DemoTable.Find (0, "Quantity"); DemoTable.Delete (TableRow); DemoTable.Columns.Remove ("Quantity"); // Similar options and their modifications can be applied to table sections and register recordsets

Creating a table with a query

If the database contains a template for the table you need, then you can use a query to quickly create a table with the desired structure.

// An example of creating an empty table based on the structure of the accumulation register // It is not hard to guess that in this way you can get a filled table Query = New Query ("SELECT THE FIRST 0 * From Accumulation Register.Products inStore"); QueryResult = Query.Run (); DemoTable = QueryResult.Upload (); // An example of creating an empty table for explicitly specified types and names of fields Query = New Query; Query.Text = "SELECT FIRST 0 | Value (Directory.Nomenclature.EmptyLink) AS Nomenclature, | EXPRESS (0 AS NUMBER (15, 3)) AS Quantity"; QueryResult = Query.Run (); DemoTable = QueryResult.Upload (); // IMPORTANT! Do not forget that the types of column values ​​obtained from a query always contain the Null type // Thus, the technical assignment created by a query always has composite column types

Conclusion

In this short article, we've covered the basic properties and best practices for creating a table of values, enough to get you started and understand. The value table object itself is so multifaceted that a detailed description of its capabilities requires writing a separate article on techniques and methods of work.

Top related articles