Exemplo n.º 1
0
        public fileToSend GenerateVacationSheduleDoc()
        {
            VacationSheduleData vacData = new VacationSheduleData(_context);
            fileToSend          file    = new fileToSend();

            byte[] docForm = GetDocumentFormById(4); //id графика отпусков в бд 4
            if (docForm == null)
            {
                return(null);
            }
            ICollection <VacationSheduleWordModel> data = vacData.GetDataGenerateVacationSheduleDoc();

            if (data == null)
            {
                file.data = docForm;
                file.name = "grafic otpuskov";
                file.mime = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
                return(file);
            }
            else
            {
                byte[] result = WordShedule.CreateDoc(data, docForm);
                file.data = result;
                file.name = "grafic otpuskov";
                file.mime = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
                return(file);
            }
        }
Exemplo n.º 2
0
        public fileToSend GenerateVacationSheduleDoc(int idOldVersionDocument)
        {
            VacationSheduleData vacData = new VacationSheduleData(_context);
            fileToSend          file    = new fileToSend();

            byte[] docForm = GetOldDocumentFormById(idOldVersionDocument); //id графика "трудовой договор для совместителей.docx" в бд 3
            ICollection <VacationSheduleWordModel> data = vacData.GetDataGenerateVacationSheduleDoc();

            if (data == null)
            {
                file.data = docForm;
                file.name = "grafic otpuskov";
                file.mime = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
                return(file);
            }
            else
            {
                byte[] result = WordShedule.CreateDoc(data, docForm);
                file.data = result;
                file.name = "grafic otpuskov";
                file.mime = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
                return(file);
            }
        }
Exemplo n.º 3
0
        public byte[] GenerateVacationShedule()
        {
            using (var stream = new MemoryStream())
                using (SpreadsheetDocument document = SpreadsheetDocument.Create(stream, SpreadsheetDocumentType.Workbook))
                {
                    WorkbookPart workbookPart = document.AddWorkbookPart();
                    workbookPart.Workbook = new Workbook();
                    WorksheetPart worksheetPart = workbookPart.AddNewPart <WorksheetPart>();

                    FileVersion fv = new FileVersion();
                    fv.ApplicationName      = "Microsoft Office Excel";
                    worksheetPart.Worksheet = new Worksheet(new SheetData());
                    WorkbookStylesPart wbsp = workbookPart.AddNewPart <WorkbookStylesPart>();
                    wbsp.Stylesheet = GenerateStyleSheet();
                    wbsp.Stylesheet.Save();

                    Columns lstColumns          = worksheetPart.Worksheet.GetFirstChild <Columns>();
                    Boolean needToInsertColumns = false;
                    if (lstColumns == null)
                    {
                        lstColumns          = new Columns();
                        needToInsertColumns = true;
                    }
                    lstColumns.Append(new Column()
                    {
                        Min = 1, Max = 1, Width = 25, CustomWidth = true
                    });
                    lstColumns.Append(new Column()
                    {
                        Min = 2, Max = 2, Width = 25, CustomWidth = true
                    });
                    lstColumns.Append(new Column()
                    {
                        Min = 3, Max = 3, Width = 25, CustomWidth = true
                    });
                    lstColumns.Append(new Column()
                    {
                        Min = 4, Max = 4, Width = 25, CustomWidth = true
                    });
                    lstColumns.Append(new Column()
                    {
                        Min = 5, Max = 5, Width = 25, CustomWidth = true
                    });
                    if (needToInsertColumns)
                    {
                        worksheetPart.Worksheet.InsertAt(lstColumns, 0);
                    }

                    Sheets sheets = workbookPart.Workbook.AppendChild(new Sheets());
                    Sheet  sheet  = new Sheet()
                    {
                        Id = workbookPart.GetIdOfPart(worksheetPart), SheetId = 1, Name = "Лист"
                    };
                    sheets.Append(sheet);

                    SheetData sheetData = worksheetPart.Worksheet.GetFirstChild <SheetData>();

                    Row row = new Row()
                    {
                        RowIndex = 1
                    };
                    sheetData.Append(row);

                    uint styleNum = 1;
                    InsertCell(row, 1, ReplaceHexadecimalSymbols("ФИО"), CellValues.String, styleNum);
                    InsertCell(row, 2, ReplaceHexadecimalSymbols("Должность"), CellValues.String, styleNum);
                    InsertCell(row, 3, ReplaceHexadecimalSymbols("Дата начала"), CellValues.String, styleNum);
                    InsertCell(row, 4, ReplaceHexadecimalSymbols("Дата окончания"), CellValues.String, styleNum);
                    InsertCell(row, 5, ReplaceHexadecimalSymbols("Заместитель"), CellValues.String, styleNum);

                    VacationSheduleData vacData = new VacationSheduleData(_context);
                    var    shedule  = vacData.GetVacationSheduleForDocument();
                    UInt32 rowIndex = 2;
                    styleNum = 2;
                    foreach (var x in shedule)
                    {
                        DateTime start = Utils.ConvertFromUnixTimestamp(x.dateStart);
                        DateTime end   = Utils.ConvertFromUnixTimestamp(x.dateEnd);
                        row = new Row()
                        {
                            RowIndex = rowIndex
                        };
                        sheetData.Append(row);

                        InsertCell(row, 1, ReplaceHexadecimalSymbols(x.fullName), CellValues.String, styleNum);
                        InsertCell(row, 2, ReplaceHexadecimalSymbols(x.position), CellValues.String, styleNum);
                        InsertCell(row, 3, ReplaceHexadecimalSymbols(start.ToShortDateString()), CellValues.String, styleNum);
                        InsertCell(row, 4, ReplaceHexadecimalSymbols(end.ToShortDateString()), CellValues.String, styleNum);
                        InsertCell(row, 5, ReplaceHexadecimalSymbols(x.replacementEmployeeName), CellValues.String, styleNum);
                        rowIndex++;
                    }

                    workbookPart.Workbook.Save();
                    document.Close();

                    //сохранить файл
                    //File.WriteAllBytes("path\\график отпусков.xlsx", stream.ToArray());

                    return(stream.ToArray());
                }
        }