本文整理汇总了C#中ExcelLibrary.SpreadSheet.Worksheet.AddPicture方法的典型用法代码示例。如果您正苦于以下问题:C# Worksheet.AddPicture方法的具体用法?C# Worksheet.AddPicture怎么用?C# Worksheet.AddPicture使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ExcelLibrary.SpreadSheet.Worksheet
的用法示例。
在下文中一共展示了Worksheet.AddPicture方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExportaExcel
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);
}
}