Показать сообщение отдельно
Старый 04.05.2010, 17:23   #1  
Roman N. Krivov is offline
Roman N. Krivov
Участник
 
25 / 11 (1) +
Регистрация: 04.05.2010
Адрес: Мир, Россия, Московская область
Вывод в Excel через Array
Доброго времени суток.

Задача: Создать отчет в Excel с табличной частью из шаблона
Решение: Есть в отчете табличная область, например, A19:CG35 (N столбцов и M строк). Я заполняю массив Array N x M раз.
X++:
protected boolean fillData()
{
    . . .
    ;
    reportRows = 0;

    . . .

        while select returnLine
            where returnLine.JournalId                  == returnTable.JournalId
        {
             inventTable = InventTable::find(returnLine.ItemId);
             custInvoiceJour = CustInvoiceJour::findFrominvoiceId(returnLine.InvoiceId);
             custInvoiceTrans = CustInvoiceTrans::findRecId(returnLine.CustInvoiceTransRecId);

            tableRows.value(tableRows.lastIndex() + 1, strfmt("%1", returnLine.ItemId));
            tableRows.value(tableRows.lastIndex() + 1, strfmt("%1", inventTable.ItemName));
            tableRows.value(tableRows.lastIndex() + 1, strfmt("%1", inventTable.ItemArticle));
            tableRows.value(tableRows.lastIndex() + 1, strfmt("%1", custInvoiceJour.InvoiceExternalId));
            tableRows.value(tableRows.lastIndex() + 1, strfmt("%1", custInvoiceJour.InvoiceDate));

            tableRows.value(tableRows.lastIndex() + 1, strfmt("%1", custInvoiceTrans.Qty));
            tableRows.value(tableRows.lastIndex() + 1, strfmt("%1", custInvoiceTrans.SalesPrice));
            tableRows.value(tableRows.lastIndex() + 1, strfmt("%1", custInvoiceTrans.amountDiscAmountInclTax()));
            tableRows.value(tableRows.lastIndex() + 1, "");
            tableRows.value(tableRows.lastIndex() + 1, "");
            tableRows.value(tableRows.lastIndex() + 1, strfmt("%1", returnLine.QtyDocument));
            tableRows.value(tableRows.lastIndex() + 1, strfmt("%1", returnLine.SummDoc));
            tableRows.value(tableRows.lastIndex() + 1, "");
            tableRows.value(tableRows.lastIndex() + 1, "");
            tableRows.value(tableRows.lastIndex() + 1, "");
            reportRows++;
        }

        return (reportRows > 0) ? true : false;
    }
    return false;
}
Далее вывожу данные массив в указанную область:
X++:
protected void fillTable()
{
    Bookmark    bookmark;
    ;

    bookmark = strfmt("%1%2:%3%4",
                    #FirstTableCol,
                    this.firstTableRow(),
                    #LastTableCol,
                    this.firstTableRow() + this.numOfRows() - 1);

    this.insertValue(bookmark, ExcelReportFromTemplate::array2variant(tableRows), 1);

}
В результате у меня первая строка дублируется M раз. ЧЯДНТ? Массив сформирован правильно. В нём строки не дублируются.

Microsoft Business Solution Axapta 3.0 Build #1951.3730/514-193 SP3/OP023071