Пример #1
0
        public void ExtractPictures()
        {           
            if (Drawing != null)
            {
                MsofbtDgContainer dgContainer = Drawing.FindChild<MsofbtDgContainer>();
                if (dgContainer != null)
                {
                    MsofbtSpgrContainer spgrContainer = dgContainer.FindChild<MsofbtSpgrContainer>();

                    List<MsofbtSpContainer> spContainers = spgrContainer.FindChildren<MsofbtSpContainer>();

                    foreach (MsofbtSpContainer spContainer in spContainers)
                    {
                        MsofbtOPT opt = spContainer.FindChild<MsofbtOPT>();
                        MsofbtClientAnchor anchor = spContainer.FindChild<MsofbtClientAnchor>();

                        if (opt != null && anchor != null)
                        {
                            foreach (ShapeProperty prop in opt.Properties)
                            {
                                if (prop.PropertyID == PropertyIDs.BlipId)
                                {
                                    int imageIndex = (int)prop.PropertyValue - 1;
                                    Picture pic = new Picture();
                                    pic.TopLeftCorner.RowIndex = anchor.Row1;
                                    pic.TopLeftCorner.ColIndex = anchor.Col1;
                                    pic.TopLeftCorner.DX = anchor.DX1;
                                    pic.TopLeftCorner.DY = anchor.DY1;
                                    pic.BottomRightCorner.RowIndex = anchor.Row2;
                                    pic.BottomRightCorner.ColIndex = anchor.Col2;
                                    pic.BottomRightCorner.DX = anchor.DX2;
                                    pic.BottomRightCorner.DY = anchor.DY2;
                                    pic.Image = Book.ExtractImage(imageIndex);
                                    pictures[pic.CellPos] = pic;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
        private void ExportaExcel(List<PontoUsuarioVO> list)
        {
            if (list.Count == 0)
            {
                this.MostrarMensagem("Alerta", "Não existem informações para serem exportadas.", String.Empty);
                return;
            }

            base.RemoverArquivosExistentes();

            Workbook workbook = new Workbook();
            FileStream stream = null;

            foreach (var group in list.GroupBy(x => x.Usuario))
            {
                Worksheet worksheet = new Worksheet("Relatório de Horas - "+ group.Key.Nome);
                String path = Path.Combine(Server.MapPath("~/ConfiguracoesSistema"), "1.jpg");

                if (File.Exists(path))
                {
                    stream = new FileStream(path, FileMode.Open, FileAccess.Read);

                    Picture pic = new Picture();
                    System.Drawing.Image imgLogo = new System.Drawing.Bitmap(stream);
                    pic.Image = new ExcelLibrary.SpreadSheet.Image(imageToByteArray(imgLogo), 0xF01D);

                    //Tamanho da imagem.
                    pic.TopLeftCorner = new CellAnchor(0, 0, 10, 10);
                    pic.BottomRightCorner = new CellAnchor(4, 2, 10, 10);

                    // Adiciona a imagem(logo).
                    worksheet.AddPicture(pic);
                }

                worksheet.Cells[2, 3] = new ExcelLibrary.SpreadSheet.Cell("");
                worksheet.Cells[2, 4] = new ExcelLibrary.SpreadSheet.Cell(DateTime.Now.ToString("dd/MM/yyyy"));

                int index = 0;
                String[] header = new String[] { "Data", "Início", "Término", "Justificativa", "Período", "Tempo" };

                index = 0;
                foreach (string strHeader in header)
                {
                    worksheet.Cells[6, index] = new ExcelLibrary.SpreadSheet.Cell(strHeader);
                    index++;
                }

                index = 0;
                int indexLinha = 7;

                foreach(var obj1 in group)
                {
                    worksheet.Cells[indexLinha, index] = new ExcelLibrary.SpreadSheet.Cell(obj1.Data.ToString("dd/MM/yyyy"));
                    index++;
                    worksheet.Cells[indexLinha, index] = new ExcelLibrary.SpreadSheet.Cell(obj1.HoraInicio.ToString("HH:mm"));
                    index++;
                    worksheet.Cells[indexLinha, index] = new ExcelLibrary.SpreadSheet.Cell(obj1.HoraTermino.HasValue ? obj1.HoraTermino.Value.ToString("HH:mm") : "");
                    index++;
                    worksheet.Cells[indexLinha, index] = new ExcelLibrary.SpreadSheet.Cell(obj1.Justificativa);
                    index++;
                    worksheet.Cells[indexLinha, index] = new ExcelLibrary.SpreadSheet.Cell(obj1.Periodo.Nome);
                    index++;
                    worksheet.Cells[indexLinha, index] = new ExcelLibrary.SpreadSheet.Cell(GetTempo(obj1.Tempo.ToInt32()));
                    index = 0;
                    indexLinha++;
                }

                Int32 min = group.Sum(x => x.Tempo).ToInt32();

                String tempo = GetTempo(min);

                worksheet.Cells[indexLinha, 4] = new ExcelLibrary.SpreadSheet.Cell("Total de Horas");
                worksheet.Cells[indexLinha, 5] = new ExcelLibrary.SpreadSheet.Cell(tempo);
                /// Adiciona o worksheet no workbook
                workbook.Worksheets.Add(worksheet);
            }

            // Nome do arquivo a ser gerado
            String nomeAux = Guid.NewGuid().ToString() + "_" + UsuarioLogado.Id.ToString();
            String caminho = Path.Combine(Server.MapPath("~/temp"), nomeAux + ".xls");
            workbook.Save(caminho);

            if (stream != null)
                stream.Close();

            FileInfo arquivo = new FileInfo(caminho);
            if (arquivo.Exists)
            {
                Response.Clear();
                Response.ContentType = "application/vnd.ms-excel";
                Response.AddHeader("Content-Disposition", "attachment;filename=RelatorioHoras.xls");
                Response.AddHeader("Content-Length", arquivo.Length.ToString());
                Response.Flush();
                Response.WriteFile(caminho);
            }
        }
Пример #3
0
 public void AddPicture(Picture pic)
 {
     pictures[pic.CellPos] = pic;
 }
Пример #4
0
 public void AddPicture(Picture pic)
 {
     pictures[pic.CellPos] = pic;
 }