Люди, помогите!
я никак не могу понять что делает get_Range(Cells[,],Cells[,])?
к тому же мне нужно использовать функцию entireRow.Group для группировки.
но всё как-то смещается в excel файле. вот код (исходником является datatable):
Код:
foreach (DataRow drow in dt.Rows)
{
if (!Equals(oldId, drow[1]))
{
row++;
ERg = ESh.get_Range(ESh.Cells[row, 1], ESh.Cells[row, dt.Columns.Count]);//для вывода элементов шапки орг-ции
//ERg.Borders.Weight = xlThin; ERg.BorderAround(xlSolid, xlMedium);
//ERg.Font.Bold = true;
ERg.Interior.ColorIndex = 35;
for (int j = 0; j < dt.Columns.Count; j++)//вывод заголовка анкеты
ERg[row, j + 1] = drow[j];
#endregion
ERg.Cells[1, 1] = Convert.ToString(drow[1]);//вывод заголовка анкеты
Ncnt = 1;//кол-во дочерних элементов
oldId = Convert.ToInt32(drow[1]);
oldRow = row + 1;
}
else
{
row++;
for (int j = 0; j < dt.Columns.Count; j++)
{
ERg[row, j + 1] = drow[j];
}
Ncnt++;
//MessageBox.Show("Дитя, строка:" + row.ToString()+" кол-во:"+Ncnt);
//oldRow = row + Ncnt + 1;
}
exportProgress.Value++;
}
if (!Equals(oldRow, -1))
{
ERg = ESh.get_Range(ESh.Cells[oldRow, 1], ESh.Cells[row, 1]);
ERg.EntireRow.Group(Type.Missing, Type.Missing, Type.Missing, Type.Missing);
/////////////////////
row++;
ERg = ESh.get_Range(ESh.Cells[row, 1], ESh.Cells[row, 37]);
ERg[1, 1] = "∑";
ERg[1, 2] = "итого";
ERg.Interior.ColorIndex = 15;
ERg.Font.Bold = true;
//ERg = ESh.get_Range(ESh.Cells[row, 1], ESh.Cells[row, 37]);
ERg.FormulaR1C1 = string.Format("=СУММ(R{0}C:R{1}C)", oldRow, row - 1);
ERg.FormulaR1C1 = string.Format("=A3", oldRow, row - 1);
/////////////////////
it = Convert.ToInt32(oldRow);
ERg = ESh.get_Range(ESh.Cells[it - 1, 1], ESh.Cells[it - 1, 37]);
ERg.FormulaR1C1 = string.Format("=СРЗНАЧ(R{0}C:R{1}C)", oldRow, row - 1);
//ERg.FormulaR1C1 = string.Format("=A3", oldRow, row - 1);
//ERg.NumberFormat = "# ##0,00";
}
#region форматирование шапки
ERg = ESh.get_Range(ESh.Cells[1, 1], ESh.Cells[row, dt.Columns.Count]);
ERg.Borders.LineStyle = xl.XlLineStyle.xlContinuous;
ERg.Borders.Weight = xl.XlBorderWeight.xlThin;
ERg.BorderAround(xl.XlLineStyle.xlContinuous, xl.XlBorderWeight.xlMedium, xl.XlColorIndex.xlColorIndexAutomatic, xl.XlColorIndex.xlColorIndexAutomatic);
ERg.EntireRow.AutoFit();
ERg = ESh.get_Range(ESh.Cells[1, 1], ESh.Cells[1, dt.Columns.Count]);
ERg.Interior.ColorIndex = 40;
ERg.BorderAround(xl.XlLineStyle.xlContinuous, xl.XlBorderWeight.xlMedium, xl.XlColorIndex.xlColorIndexAutomatic, xl.XlColorIndex.xlColorIndexAutomatic);
ERg.RowHeight = 35;
ERg.HorizontalAlignment = xl.XlHAlign.xlHAlignCenter;
ERg.VerticalAlignment = xl.XlVAlign.xlVAlignCenter;
ERg.WrapText = true;
ERg.EntireColumn.AutoFit();
#endregion
row++;
ERg = ESh.get_Range(ESh.Cells[frow - 1, 37 + 1], ESh.Cells[row - 1, 37 + 1]);
ERg.Borders.LineStyle = xl.XlLineStyle.xlContinuous;
ERg.Borders.Weight = xl.XlBorderWeight.xlThin;
ERg.BorderAround(xl.XlLineStyle.xlContinuous, xl.XlBorderWeight.xlMedium, xl.XlColorIndex.xlColorIndexAutomatic, xl.XlColorIndex.xlColorIndexAutomatic);
ERg.FormulaR1C1 = "=СРЗНАЧ(RC[-13]:RC[-1])";
// ERg.FormulaR1C1 = string.Format("=A3", oldRow, row - 1);
ERg.Interior.ColorIndex = 15;
ERg[1, 1] = "Итого";
ERg.Font.Bold = true;
//ERg.NumberFormat = "# ##0,00";
//--------------------------------------------------------
//ESh.get_Range(ESh.Cells[frow - 1, 3], ESh.Cells[frow - 1, 3]).Select();
//xlApp.ActiveWindow.FreezePanes = true;
ERg = ESh.get_Range(ESh.Cells[1, 1], ESh.Cells[1, 1]);
ERg.ColumnWidth = 3.5;
xlApp.ActiveWindow.Zoom = 85;
xlApp.Visible = true;