Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > .NET Frameworks (точка нет фреймворки) > C# (си шарп)
Регистрация

Восстановить пароль
Повторная активизация e-mail

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 22.04.2011, 12:48   #1
lildare
 
Регистрация: 25.03.2011
Сообщений: 8
По умолчанию выгрузка в Excel файл

Люди, помогите!
я никак не могу понять что делает 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;
lildare вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
выгрузка в Excel по шаблону Swatch Microsoft Office Access 4 10.11.2010 23:46
Выгрузка из DBGrid в Excel Nika03 БД в Delphi 1 19.05.2010 22:06
Выгрузка Excel и выборка asale Общие вопросы Delphi 3 03.05.2010 12:11
Выгрузка в dbf файл span4 SQL, базы данных 4 04.06.2009 15:56
выгрузка в файл zetrix БД в Delphi 0 30.10.2006 12:50