Ejemplo n.º 1
0
        private void MakeHead <T>(T item)
        {
            Type t = typeof(T);
            int  i = 0;

            foreach (var info in t.GetProperties())
            {
                DisplayAttribute dispAttr = (DisplayAttribute)Attribute.GetCustomAttribute(info, typeof(DisplayAttribute));
                UIHintAttribute  uiAttr   = (UIHintAttribute)Attribute.GetCustomAttribute(info, typeof(UIHintAttribute));

                if (uiAttr != null && uiAttr.UIHint == "HiddenInput")
                {
                    continue;
                }

                if (dispAttr != null)
                {
                    ws.AddCell(0, i, dispAttr.Name);
                }
                else
                {
                    ws.AddCell(0, i, info.Name);
                }
                i++;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Resolves the workbook with all worksheets from the loaded file
        /// </summary>
        /// <returns>Workbook object</returns>
        public Workbook GetWorkbook()
        {
            Workbook wb = new Workbook(false);

            wb.SetImportState(true);
            Worksheet ws;

            foreach (KeyValuePair <int, WorksheetReader> reader in worksheets)
            {
                WorkbookReader.WorksheetDefinition definition = workbook.WorksheetDefinitions[reader.Key];
                ws        = new Worksheet(definition.WorksheetName, definition.SheetID, wb);
                ws.Hidden = definition.Hidden;
                foreach (KeyValuePair <string, Cell> cell in reader.Value.Data)
                {
                    cell.Value.WorksheetReference = ws;
                    if (reader.Value.StyleAssignment.ContainsKey(cell.Key))
                    {
                        Style style = styleReaderContainer.GetStyle(reader.Value.StyleAssignment[cell.Key], true);
                        if (style != null)
                        {
                            cell.Value.SetStyle(style);
                        }
                    }
                    ws.AddCell(cell.Value, cell.Key);
                }
                wb.AddWorksheet(ws);
            }
            wb.SetImportState(false);
            return(wb);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Resolves the workbook with all worksheets from the loaded file
        /// </summary>
        /// <returns>Workbook object</returns>
        public Workbook GetWorkbook()
        {
            Workbook  wb = new Workbook(false);
            Worksheet ws;
            int       index = 1;

            foreach (KeyValuePair <int, WorksheetReader> reader in worksheets)
            {
                ws = new Worksheet(workbook.WorksheetDefinitions[reader.Key], index, wb);
                foreach (KeyValuePair <string, Cell> cell in reader.Value.Data)
                {
                    cell.Value.WorksheetReference = ws;
                    if (reader.Value.StyleAssignment.ContainsKey(cell.Key))
                    {
                        Style style = styleReaderContainer.GetStyle(reader.Value.StyleAssignment[cell.Key], true);
                        if (style != null)
                        {
                            cell.Value.SetStyle(style);
                        }
                    }
                    ws.AddCell(cell.Value, cell.Key);
                }
                wb.AddWorksheet(ws);
                index++;
            }
            return(wb);
        }
Ejemplo n.º 4
0
        public ActionResult Export()
        {
            string   result = string.Empty;
            Workbook wb     = new Workbook();

            // properties
            wb.Properties.Author    = "Calabonga";
            wb.Properties.Created   = DateTime.Today;
            wb.Properties.LastAutor = "Calabonga";
            wb.Properties.Version   = "14";

            // options sheets
            wb.ExcelWorkbook.ActiveSheet       = 1;
            wb.ExcelWorkbook.DisplayInkNotes   = false;
            wb.ExcelWorkbook.FirstVisibleSheet = 1;
            wb.ExcelWorkbook.ProtectStructure  = false;
            wb.ExcelWorkbook.WindowHeight      = 800;
            wb.ExcelWorkbook.WindowTopX        = 0;
            wb.ExcelWorkbook.WindowTopY        = 0;
            wb.ExcelWorkbook.WindowWidth       = 600;


            // get data
            List <EntranceComposition> entranceCompositions = db.EntranceComposition.ToList();
            Worksheet ws3 = new Worksheet("Поставки");

            ws3.AddCell(0, 0, "Поставка");
            ws3.AddCell(0, 1, "Ингредиент");
            ws3.AddCell(0, 2, "Количество");
            ws3.AddCell(0, 3, "Цена");
            int totalRows = 0;

            // appending rows with data
            for (int i = 0; i < entranceCompositions.Count; i++)
            {
                ws3.AddCell(i + 1, 0, entranceCompositions[i].Entrance);
                ws3.AddCell(i + 1, 1, entranceCompositions[i].Ingredient1.Name.ToString());
                ws3.AddCell(i + 1, 2, entranceCompositions[i].Count);
                ws3.AddCell(i + 1, 3, entranceCompositions[i].Cost);
                totalRows++;
            }

            wb.AddWorksheet(ws3);

            // generate xml
            string workstring = wb.ExportToXML();

            // Send to user file
            return(new ExcelResult("Entrances.xls", workstring));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Resolves the workbook with all worksheets from the loaded file
        /// </summary>
        /// <returns>Workbook object</returns>
        public Workbook GetWorkbook()
        {
            Workbook        wb = new Workbook(false);
            WorksheetReader wr;
            Worksheet       ws;

            for (int i = 0; i < worksheets.Count; i++)
            {
                wr = worksheets[i];
                ws = new Worksheet(workbook.WorksheetDefinitions[i + 1], i + 1, wb);
                foreach (KeyValuePair <string, Cell> cell in wr.Data)
                {
                    ws.AddCell(cell.Value, cell.Key);
                }
                wb.AddWorksheet(ws);
            }
            return(wb);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Resolves the workbook with all worksheets from the loaded file
        /// </summary>
        /// <returns>Workbook object</returns>
        public Workbook GetWorkbook()
        {
            Workbook  wb = new Workbook(false);
            Worksheet ws;
            int       index = 1;

            foreach (KeyValuePair <int, WorksheetReader> reader in worksheets)
            {
                ws = new Worksheet(workbook.WorksheetDefinitions[reader.Key], index, wb);
                foreach (KeyValuePair <string, Cell> cell in reader.Value.Data)
                {
                    ws.AddCell(cell.Value, cell.Key);
                }
                wb.AddWorksheet(ws);
                index++;
            }
            return(wb);
        }
Ejemplo n.º 7
0
        public static string Build(List <Ttn> items, string title = "Без заголовка")
        {
            var workbook = new Workbook();

            PropertiesBuilder.Apply(workbook);
            StylesBuilder.Apply(workbook);

            // create first worksheet
            var worksheet = new Worksheet("Лист 1");

            worksheet.AddCellWithStyle(0, 0, title, StylesBuilder.TitleStyle, 6U);

            // adding headers
            worksheet.AddCellWithStyle(1, 0, "Номер заказа", StylesBuilder.Headerstyle);
            worksheet.AddCellWithStyle(1, 1, "Дата заказа", StylesBuilder.Headerstyle);
            worksheet.AddCellWithStyle(1, 2, "Артикул товара", StylesBuilder.Headerstyle);
            worksheet.AddCellWithStyle(1, 3, "Наименование товара", StylesBuilder.Headerstyle);
            worksheet.AddCellWithStyle(1, 4, "Количество", StylesBuilder.Headerstyle);
            worksheet.AddCellWithStyle(1, 5, "Цена", StylesBuilder.Headerstyle);
            worksheet.AddCellWithStyle(1, 6, "Сумма", StylesBuilder.Headerstyle);

            var row = 2;

            foreach (var item in items)
            {
                worksheet.AddCell(row, 0, item.Id);
                worksheet.AddCell(row, 1, item.OrderDate.ToString());
                worksheet.AddCell(row, 2, item.ProductId);
                worksheet.AddCell(row, 3, item.ProductName);
                worksheet.AddCell(row, 4, item.Quantity);
                worksheet.AddCell(row, 5, item.UnitPrice);
                worksheet.AddCellWithFormula(row, 6, 0, "=RC[-2]*RC[-1]");
                row++;
            }

            // appending footer with formulas
            worksheet.AddCellWithStyle(row, 0, string.Empty, StylesBuilder.SummaryStyle);
            worksheet.AddCellWithStyle(row, 1, string.Empty, StylesBuilder.SummaryStyle);
            worksheet.AddCellWithStyle(row, 2, string.Empty, StylesBuilder.SummaryStyle);
            worksheet.AddCellWithStyle(row, 3, string.Empty, StylesBuilder.SummaryStyle);
            worksheet.AddCellWithStyle(row, 4, string.Empty, StylesBuilder.SummaryStyle);
            worksheet.AddCellWithStyleAndFormula(row, 5, 0, "=AVERAGE(R[-" + (row - 1) + "]C:R[-1]C)", StylesBuilder.SummaryStyle);
            worksheet.AddCellWithStyleAndFormula(row, 6, 0, "=SUM(R[-" + (row - 1) + "]C:R[-1]C)", StylesBuilder.SummaryStyle);

            workbook.AddWorksheet(worksheet);
            return(workbook.ExportToXML());
        }
Ejemplo n.º 8
0
        public ActionResult Export()
        {
            string   result = string.Empty;
            Workbook wb     = new Workbook();

            // properties
            wb.Properties.Author    = "Calabonga";
            wb.Properties.Created   = DateTime.Today;
            wb.Properties.LastAutor = "Calabonga";
            wb.Properties.Version   = "14";

            // options sheets
            wb.ExcelWorkbook.ActiveSheet       = 1;
            wb.ExcelWorkbook.DisplayInkNotes   = false;
            wb.ExcelWorkbook.FirstVisibleSheet = 1;
            wb.ExcelWorkbook.ProtectStructure  = false;
            wb.ExcelWorkbook.WindowHeight      = 800;
            wb.ExcelWorkbook.WindowTopX        = 0;
            wb.ExcelWorkbook.WindowTopY        = 0;
            wb.ExcelWorkbook.WindowWidth       = 600;
            // get data
            List <Machinist> people = db.Machinist.ToList();
            Worksheet        ws3    = new Worksheet("Пользователи");

            ws3.AddCell(0, 0, "Фио");
            ws3.AddCell(0, 1, "Аддрес");
            ws3.AddCell(0, 2, "Телефон");



            // appending rows with data
            for (int i = 0; i < people.Count; i++)
            {
                ws3.AddCell(i + 1, 0, people[i].FIO);
                ws3.AddCell(i + 1, 1, people[i].Address);
                ws3.AddCell(i + 1, 2, people[i].Telephone);
            }

            wb.AddWorksheet(ws3);

            // generate xml
            string workstring = wb.ExportToXML();

            // Send to user file
            return(new ExcelResult("Persons.xls", workstring));
        }
        public ActionResult Export()
        {
            string   result = string.Empty;
            Workbook wb     = new Workbook();

            // properties
            wb.Properties.Author    = "Calabonga";
            wb.Properties.Created   = DateTime.Today;
            wb.Properties.LastAutor = "Calabonga";
            wb.Properties.Version   = "14";

            // options sheets
            wb.ExcelWorkbook.ActiveSheet       = 1;
            wb.ExcelWorkbook.DisplayInkNotes   = false;
            wb.ExcelWorkbook.FirstVisibleSheet = 1;
            wb.ExcelWorkbook.ProtectStructure  = false;
            wb.ExcelWorkbook.WindowHeight      = 800;
            wb.ExcelWorkbook.WindowTopX        = 0;
            wb.ExcelWorkbook.WindowTopY        = 0;
            wb.ExcelWorkbook.WindowWidth       = 600;

            // create style s1 for header
            //Style s1 = new Style("s1");
            //s1.Font.Bold = true;
            //s1.Font.Italic = true;
            //s1.Font.Color = "#FF0000";
            //wb.AddStyle(s1);

            //// create style s2 for header
            //Style s2 = new Style("s2");
            //s2.Font.Bold = true;
            //s2.Font.Italic = true;
            //s2.Font.Size = 12;
            //s2.Borders.Add(new Border());
            //s2.Font.Color = "#0000FF";
            //wb.AddStyle(s2);
            //// Third sheet
            //

            //// Adding Headers


            // get data
            List <AspNetUsers> people = GetUsers();
            Worksheet          ws3    = new Worksheet("Пользователи");

            ws3.AddCell(0, 0, "Фио");
            ws3.AddCell(0, 1, "Пароль");
            ws3.AddCell(0, 2, "Соль");
            ws3.AddCell(0, 3, "Почта");
            ws3.AddCell(0, 4, "UserName");
            int totalRows = 0;

            // appending rows with data
            for (int i = 0; i < people.Count; i++)
            {
                ws3.AddCell(i + 1, 0, people[i].Fio);
                ws3.AddCell(i + 1, 1, people[i].PasswordHash);
                ws3.AddCell(i + 1, 2, people[i].SecurityStamp);
                ws3.AddCell(i + 1, 3, people[i].Email);
                ws3.AddCell(i + 1, 4, people[i].UserName);
                totalRows++;
            }



            wb.AddWorksheet(ws3);

            // generate xml
            string workstring = wb.ExportToXML();

            // Send to user file
            return(new ExcelResult("Persons.xls", workstring));
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Build Excel file
        /// </summary>
        /// <param name="items">product</param>
        /// <param name="title"></param>
        /// <returns></returns>
        public static string Build(List <Ttn> items, string title = "Без заголовка")
        {
            var workbook = new Workbook();

            PropertiesBuilder.Apply(workbook);
            StylesBuilder.Apply(workbook);

            // create first worksheet
            var worksheet = new Worksheet("Лист 1");

            worksheet.AddCellWithStyle(0, 0, title, StylesBuilder.TitleStyle, 6U);

            // adding headers
            worksheet.AddCellWithStyle(1, 0, "ТТН № ", StylesBuilder.Headerstyle);
            worksheet.AddCellWithStyle(1, 1, "Дата", StylesBuilder.Headerstyle);
            worksheet.AddCellWithStyle(1, 2, "Время", StylesBuilder.Headerstyle);
            worksheet.AddCellWithStyle(1, 3, "Продукция", StylesBuilder.Headerstyle);
            worksheet.AddCellWithStyle(1, 4, "Кол", StylesBuilder.Headerstyle);

            worksheet.AddCellWithStyle(1, 5, "Цена", StylesBuilder.Headerstyle);
            worksheet.AddCellWithStyle(1, 6, "Сумма", StylesBuilder.Headerstyle);
            worksheet.AddCellWithStyle(1, 7, "Модель", StylesBuilder.Headerstyle);
            worksheet.AddCellWithStyle(1, 8, "Автобаза", StylesBuilder.Headerstyle);
            worksheet.AddCellWithStyle(1, 9, "Гос. №", StylesBuilder.Headerstyle);
            worksheet.AddCellWithStyle(1, 10, "Водитель", StylesBuilder.Headerstyle);
            worksheet.AddCellWithStyle(1, 11, "Адрес", StylesBuilder.Headerstyle);

            var row = 2;

            foreach (var item in items)
            {
                worksheet.AddCell(row, 0, item.Num);
                worksheet.AddCell(row, 1, item.Dat.ToString());
                worksheet.AddCell(row, 2, item.Tm);
                worksheet.AddCell(row, 3, item.Good);
                worksheet.AddCell(row, 4, item.Kol);

                worksheet.AddCell(row, 5, item.Price);
                worksheet.AddCell(row, 6, item.Sm);
                worksheet.AddCell(row, 7, item.Amodel);
                worksheet.AddCell(row, 8, item.Ab);
                worksheet.AddCell(row, 9, item.Gn);
                worksheet.AddCell(row, 10, item.Driv);
                worksheet.AddCell(row, 11, item.Adres);
                row++;
            }

            // appending footer with formulas
            //worksheet.AddCellWithStyle(row, 0, string.Empty, StylesBuilder.SummaryStyle);
            //worksheet.AddCellWithStyle(row, 1, string.Empty, StylesBuilder.SummaryStyle);
            //worksheet.AddCellWithStyle(row, 2, string.Empty, StylesBuilder.SummaryStyle);
            //worksheet.AddCellWithStyle(row, 3, string.Empty, StylesBuilder.SummaryStyle);
            //worksheet.AddCellWithStyle(row, 4, string.Empty, StylesBuilder.SummaryStyle);
            //worksheet.AddCellWithStyleAndFormula(row, 5, 0, "=AVERAGE(R[-" + (row - 1) + "]C:R[-1]C)", StylesBuilder.SummaryStyle);
            //worksheet.AddCellWithStyleAndFormula(row, 6, 0, "=SUM(R[-" + (row - 1) + "]C:R[-1]C)", StylesBuilder.SummaryStyle);

            workbook.AddWorksheet(worksheet);
            return(workbook.ExportToXML());
        }
Ejemplo n.º 11
0
        public ExcelResult Export(int id)
        {
            string   result = string.Empty;
            Workbook wb     = new Workbook();

            // properties
            wb.Properties.Author    = "Calabonga";
            wb.Properties.Created   = DateTime.Today;
            wb.Properties.LastAutor = "Calabonga";
            wb.Properties.Version   = "14";

            // options sheets
            wb.ExcelWorkbook.ActiveSheet       = 1;
            wb.ExcelWorkbook.DisplayInkNotes   = false;
            wb.ExcelWorkbook.FirstVisibleSheet = 1;
            wb.ExcelWorkbook.ProtectStructure  = false;
            wb.ExcelWorkbook.WindowHeight      = 800;
            wb.ExcelWorkbook.WindowTopX        = 0;
            wb.ExcelWorkbook.WindowTopY        = 0;
            wb.ExcelWorkbook.WindowWidth       = 600;

            // First sheet
            Worksheet ws1 = new Worksheet("Sheet");

            // Adding Headers
            ws1.AddCell(0, 0, "");
            ws1.AddCell(0, 1, "Начальное сальдо", mergeAcross: 1);
            ws1.AddCell(0, 3, "Текущие показатели", mergeAcross: 1);
            ws1.AddCell(0, 5, "Конечное сальдо", 1);
            ws1.AddCell(1, 0, "Б/сч");
            ws1.AddCell(1, 1, "Актив");
            ws1.AddCell(1, 2, "Пассив");
            ws1.AddCell(1, 3, "Актив");
            ws1.AddCell(1, 4, "Пассив");
            ws1.AddCell(1, 5, "Актив");
            ws1.AddCell(1, 6, "Пассив");

            // get data
            AccountingContext   context = new AccountingContext();
            List <AccountField> people  = context.Fields.Where(x => x.UploadedFileInfoId == id).ToList();

            int p = 0;

            // appending rows with data
            for (int i = 1; i <= people.Count; i++)
            {
                ws1.AddCell(i + 1, 0, people[p].FieldAccountUnit);
                ws1.AddCell(i + 1, 1, people[p].IncomingBalanceFieldAsset);
                ws1.AddCell(i + 1, 2, people[p].IncomingBalanceFieldLiability);
                ws1.AddCell(i + 1, 3, people[p].CurrentAssetsFieldAsset);
                ws1.AddCell(i + 1, 4, people[p].CurrentAssetsFieldLiability);
                ws1.AddCell(i + 1, 5, people[p].OutgoingBalanceFieldAsset);
                ws1.AddCell(i + 1, 6, people[p].OutgoingBalanceFieldLiability);
                p++;
            }

            wb.AddWorksheet(ws1);

            // generate xml
            string workstring = wb.ExportToXML();

            // Send to user file
            return(new ExcelResult("TurnoverBalanceSheet.xls", workstring));
        }
        public void genExcel(int id)
        {
            var logs = db.Logs.Where(p => p.CourseId == id);

            ViewBag.ratings = db.Ratings.Join(logs.DefaultIfEmpty(), p => p.LogId, c => c.LogId,
                                              (p, c) => new Rate
            {
                RatingId  = p.RatingId,
                StudentId = p.StudentId,
                Value     = p.Value,
                LogId     = p.LogId
            }
                                              ).ToList();
            ViewBag.logs = logs.ToList();
            var courseMembers = db.CourseMembers.Where(p => p.CourseId == id);

            ViewBag.students = db.Students.Join(courseMembers.DefaultIfEmpty(), p => p.StudentId, c => c.StudentId,
                                                (p, c) => new Stud
            {
                StudentId = p.StudentId,
                Name      = p.Name,
                Surname   = p.Surname
            }
                                                ).ToList();

            Workbook  wb = new Workbook();
            Worksheet ws = new Worksheet("ws");

            ws.AddCell(0, 0, "----------");
            int i = 1;

            foreach (var item in ViewBag.logs)
            {
                ws.AddCell(0, i, item.Title);
                i++;
            }
            i = 1;
            foreach (var item in ViewBag.students)
            {
                int y = 1;
                ws.AddCell(i, 0, item.Name + " " + item.Surname);
                foreach (var item2 in ViewBag.ratings)
                {
                    if (item2.StudentId == item.StudentId)
                    {
                        if (item2.Value == null)
                        {
                            ws.AddCell(i, y, "");
                        }
                        else
                        {
                            ws.AddCell(i, y, @item2.Value);
                        }
                        y++;
                    }
                }
                i++;
            }
            wb.AddWorksheet(ws);

            string filename   = "Rating.xls";
            string workstring = wb.ExportToXML();

            HttpContext.Response.Headers.Add("content-disposition", string.Format("attachment; filename={0}", filename));
            HttpContext.Response.ContentType = "application/vnd.ms-excel";
            HttpContext.Response.WriteAsync(workstring);
        }
Ejemplo n.º 13
0
        public ExcelResult Export()
        {
            string   result = string.Empty;
            Workbook wb     = new Workbook();

            // properties
            wb.Properties.Author    = "Grapart";
            wb.Properties.Created   = DateTime.Today;
            wb.Properties.LastAutor = "Grapart";
            wb.Properties.Version   = "14";

            // options sheets
            wb.ExcelWorkbook.ActiveSheet       = 1;
            wb.ExcelWorkbook.DisplayInkNotes   = false;
            wb.ExcelWorkbook.FirstVisibleSheet = 1;
            wb.ExcelWorkbook.ProtectStructure  = false;
            wb.ExcelWorkbook.WindowHeight      = 800;
            wb.ExcelWorkbook.WindowTopX        = 0;
            wb.ExcelWorkbook.WindowTopY        = 0;
            wb.ExcelWorkbook.WindowWidth       = 600;

            // create style s1 for header
            Style s1 = new Style("s1");

            s1.Font.Bold   = true;
            s1.Font.Italic = true;
            s1.Font.Color  = "#21610B";
            wb.AddStyle(s1);

            // create style s2 for header
            Style s2 = new Style("s2");

            s2.Font.Bold   = true;
            s2.Font.Italic = true;
            s2.Borders.Add(new Border());
            s2.Font.Color = "#0000FF";
            wb.AddStyle(s2);

            //s3
            Style s3 = new Style("s3");

            s3.Font.Bold   = true;
            s3.Font.Italic = true;
            s3.Borders.Add(new Border());
            s3.Font.Color = "#FF0000";
            wb.AddStyle(s3);

            // First sheet
            Worksheet ws3 = new Worksheet("Лист 1");

            //adding headers
            string summary = "Згенеровано і розв'язано 5 задач різних розмірностей.";

            ws3.AddCellWithStyle(0, 0, summary, s3.ID, 10, 0);
            summary = "Граф представляється списком ребер. І і ІІ - вершини ребра.";
            ws3.AddCellWithStyle(1, 0, summary, s3.ID, 10, 0);
            summary = "Значення true у колонці алгоритму - ребро входить у розріз за результатом розбиття відповідним алгоритмом.";
            ws3.AddCellWithStyle(2, 0, summary, s3.ID, 10, 0);

            int totalRows = 4;

            // appending rows with data
            foreach (var table in resultTables)
            {
                ws3.AddCellWithStyle(totalRows, 0, "I", s1.ID);
                ws3.AddCellWithStyle(totalRows, 1, "II", s1.ID);
                ws3.AddCellWithStyle(totalRows, 2, "Вага", s1.ID);
                ws3.AddCellWithStyle(totalRows, 3, "ФМ", s1.ID);
                ws3.AddCellWithStyle(totalRows, 4, "Бджолиний", s1.ID);
                for (int i = 0; i < table.Partition.Count; i++)
                {
                    ws3.AddCell(totalRows + 1, 0, table.Partition[i].first_vertex);
                    ws3.AddCell(totalRows + 1, 1, table.Partition[i].second_vertex);
                    ws3.AddCell(totalRows + 1, 2, table.Partition[i].weight);
                    ws3.AddCell(totalRows + 1, 3, Convert.ToString(table.Partition[i].fmPartition));
                    ws3.AddCell(totalRows + 1, 4, Convert.ToString(table.Partition[i].beePartition));
                    totalRows++;
                }
                ws3.AddCellWithStyle(totalRows + 1, 0, "Розріз:", s2.ID);
                //ws3.AddCellWithStyle(totalRows+1, 0, "ФМ: ", s2.ID);
                ws3.AddCell(totalRows + 1, 1, "");
                ws3.AddCell(totalRows + 1, 2, "");
                ws3.AddCellWithStyle(totalRows + 1, 3, table.fm_cutWeight, s2.ID);
                //totalRows++;
                //totalRows++;
                //ws3.AddCellWithStyle(totalRows+1, 0, "Бджолиний: ", s2.ID);
                ws3.AddCellWithStyle(totalRows + 1, 4, table.bee_cutWeight, s2.ID);
                totalRows++;
                totalRows++;
                totalRows++;
            }



            wb.AddWorksheet(ws3);

            // generate xml
            string workstring = wb.ExportToXML();

            // Send to user file
            return(new ExcelResult("ExpResult.xls", workstring));
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Build Excel file
        /// </summary>
        /// <param name="items">product</param>
        /// <param name="title"></param>
        /// <returns></returns>
        ///

        public ActionResult Export()
        {
            var result = string.Empty;
            var wb     = new Workbook();

            // properties
            wb.Properties.Author    = "ABZ";
            wb.Properties.Created   = DateTime.Today;
            wb.Properties.LastAutor = "ABZ";
            wb.Properties.Version   = "14";

            // options sheets
            wb.ExcelWorkbook.ActiveSheet       = 1;
            wb.ExcelWorkbook.DisplayInkNotes   = false;
            wb.ExcelWorkbook.FirstVisibleSheet = 1;
            wb.ExcelWorkbook.ProtectStructure  = false;
            wb.ExcelWorkbook.WindowHeight      = 800;
            wb.ExcelWorkbook.WindowTopX        = 0;
            wb.ExcelWorkbook.WindowTopY        = 0;
            wb.ExcelWorkbook.WindowWidth       = 600;

            // create style s1 for header
            var s1 = new Style("s1")
            {
                Font = new Font {
                    Bold = true, Italic = true, Color = "#FF0000"
                }
            };

            wb.AddStyle(s1);

            // create style s2 for header
            var s2 = new Style("s2")
            {
                Font = new Font {
                    Bold = true, Italic = true, Size = 12, Color = "#0000FF"
                }
            };

            wb.AddStyle(s2);

            var ws3 = new Worksheet("Реестр отпущенной продукции");

            // Adding Headers
            ws3.AddCell(0, 0, "ТТН № ", 0);
            ws3.AddCell(0, 1, "Дата", 0);
            ws3.AddCell(0, 2, "Время", 0);
            ws3.AddCell(0, 3, "Продукция", 0);
            ws3.AddCell(0, 4, "Кол", 0);

            ws3.AddCell(0, 5, "Цена", 0);
            ws3.AddCell(0, 6, "Сумма", 0);
            ws3.AddCell(0, 7, "Модель", 0);
            ws3.AddCell(0, 8, "Автобаза", 0);
            ws3.AddCell(0, 9, "Гос. №", 0);
            ws3.AddCell(0, 10, "Водитель", 0);
            ws3.AddCell(0, 11, "Адрес", 0);

            // get data
            int dm = (int)Session["Month"];

            int year = (int)Session["Year"];

            //Установили 1е число
            DateTime begDt = new DateTime(year, dm, 01, 0, 0, 0);
            //Установили 1е число следующего месяца
            DateTime      endDt = begDt.AddMonths(1);
            TtnRepository repo  = new TtnRepository();
            List <Ttn>    ttn   = repo.GetTtn(Cust.CustId, begDt, endDt);

            int totalRows = 0;

            // appending rows with data
            for (int i = 0; i < ttn.Count; i++)
            {
                ws3.AddCell(i + 1, 0, ttn[i].Num, 0);
                ws3.AddCell(i + 1, 1, ttn[i].Dat, 0);
                ws3.AddCell(i + 1, 2, ttn[i].Tm, 0);
                ws3.AddCell(i + 1, 3, ttn[i].Good, 0);
                ws3.AddCell(i + 1, 4, ttn[i].Kol, 0);

                ws3.AddCell(i + 1, 5, ttn[i].Price, 0);
                ws3.AddCell(i + 1, 6, ttn[i].Sm, 0);
                ws3.AddCell(i + 1, 7, ttn[i].Amodel, 0);
                ws3.AddCell(i + 1, 8, ttn[i].Ab, 0);
                ws3.AddCell(i + 1, 9, ttn[i].Gn, 0);
                ws3.AddCell(i + 1, 10, ttn[i].Driv, 0);
                ws3.AddCell(i + 1, 11, ttn[i].Adres, 0);

                totalRows++;
            }
            totalRows++;

            wb.AddWorksheet(ws3);

            // generate xml
            var workstring = wb.ExportToXML();

            // Send to user file
            return(new ExcelResult("Reestr.xlsx", workstring));
        }