本文整理汇总了C#中ClosedXML.Excel.XLWorkbook.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# XLWorkbook.Dispose方法的具体用法?C# XLWorkbook.Dispose怎么用?C# XLWorkbook.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ClosedXML.Excel.XLWorkbook
的用法示例。
在下文中一共展示了XLWorkbook.Dispose方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: read_excel_header
public string read_excel_header()
{
try
{
if (HttpContext.Current.Session["username"] == null)
{
return "<span style='color:red'>Session Time-out. Please Log-in Again</span>";
}
}
catch (Exception ex)
{
return "<span style='color:red'>Session Time-out. Please Log-in Again</span>";
}
string x = "";
string filename = Server.MapPath("~\\pdf\\" + HttpContext.Current.Session["username"] + "\\Nutratech_DTR.xlsx");
StringBuilder sb = new StringBuilder();
if (File.Exists(filename))
{
XLWorkbook workbook = new XLWorkbook(filename);
IXLWorksheet ws = workbook.Worksheet(1);
IXLCell cell = ws.Cell(4, 1);
string cell_department = cell.GetString();
cell = ws.Cell(3, 1);
string cell_daterange = cell.GetString();
cell_daterange = cell_daterange.Replace("DATE RANGE : ", "");
sb.Append("[");
sb.Append("{");
try
{
sb.Append("\"department\":\"" + cell_department.Replace("DEPARTMENT : ", "") + "\",");
}
catch (Exception ex)
{
sb.Append("\"department\":\"" + "" + "\",");
}
try
{
sb.Append("\"date_from\":\"" + cell_daterange.Substring(0, cell_daterange.IndexOf(" - ")).Trim() + "\",");
}
catch (Exception ex)
{
sb.Append("\"date_from\":\"" + "" + "\",");
}
try
{
sb.Append("\"date_to\":\"" + cell_daterange.Substring(cell_daterange.IndexOf(" - ") + 3).Trim() + "\"");
}
catch (Exception ex)
{
sb.Append("\"date_to\":\"" + "" + "\"");
}
sb.Append("}");
sb.Append("]");
ws.Dispose();
workbook.Dispose();
}
return sb.ToString();
}
示例2: GetSpecificationFile
//.........这里部分代码省略.........
// validation = workSheet.Cell(row, 9).SetDataValidation();
// validation.AllowedValues = XLAllowedValues.List;
// validation.InCellDropdown = true;
// validation.Operator = XLOperator.Between;
// validation.List(protectFactRange);
// workSheet.Cell(row, 9).Value =
// facts.First(x => x.Id == calculation.ProtectFact.Id).Value;
// workSheet.Cell(row, 10).Value = calculation.ProtectCondition;
// workSheet.Cell(row, 11).Value = calculation.Comment;
//}
}
else
{
//var validation = workSheet.Cell(row, 12).SetDataValidation();
//validation.AllowedValues = XLAllowedValues.List;
//validation.InCellDropdown = true;
//validation.Operator = XLOperator.Between;
//validation.List(deliveryTimeRange);
//validation = workSheet.Cell(row, 13).SetDataValidation();
//validation.AllowedValues = XLAllowedValues.List;
//validation.InCellDropdown = true;
//validation.Operator = XLOperator.Between;
//validation.List(protectFactRange);
ExcelDataFormatCalcRow(ref workSheet, row, deliveryTimeRange, protectFactRange);
//Специально добавляем строчу так как мы делаем специально две на позицию чтобы ыбло удобнее добавлять руками в Экселе
row++;
ExcelDataFormatCalcRow(ref workSheet, row, deliveryTimeRange, protectFactRange);
//row++;
//var validation = workSheet.Cell(row, 6).SetDataValidation();
//validation.AllowedValues = XLAllowedValues.List;
//validation.InCellDropdown = true;
//validation.Operator = XLOperator.Between;
//validation.List(currenciesRange);
//validation = workSheet.Cell(row, 9).SetDataValidation();
//validation.AllowedValues = XLAllowedValues.List;
//validation.InCellDropdown = true;
//validation.Operator = XLOperator.Between;
//validation.List(protectFactRange);
}
//row++;
}
var list = workSheet.Range(workSheet.Cell(4, 1), workSheet.Cell(row, 17));
list.Style.Border.SetBottomBorder(XLBorderStyleValues.Thin);
list.Style.Border.SetBottomBorderColor(XLColor.Gray);
list.Style.Border.SetTopBorder(XLBorderStyleValues.Thin);
list.Style.Border.SetTopBorderColor(XLColor.Gray);
list.Style.Border.SetRightBorder(XLBorderStyleValues.Thin);
list.Style.Border.SetRightBorderColor(XLColor.Gray);
list.Style.Border.SetLeftBorder(XLBorderStyleValues.Thin);
list.Style.Border.SetLeftBorderColor(XLColor.Gray);
//workSheet.Columns(1, 11).AdjustToContents();
//workSheet.Column(8).Hide();
excBook.SaveAs(ms);
excBook.Dispose();
ms.Seek(0, SeekOrigin.Begin);
}
else
{
error = true;
message = "Нет позиций для расчета";
}
}
else
{
error = true;
message = "Нет позиций для расчета";
}
}
catch (Exception)
{
error = true;
message = "Ошибка сервера";
}
finally
{
if (excBook != null)
{
excBook.Dispose();
}
}
if (!error)
{
return new FileStreamResult(ms, "application/vnd.ms-excel")
{
FileDownloadName = "Specification_" + claimId + ".xlsx"
};
}
else
{
ViewBag.Message = message;
return View();
}
}
示例3: Cabecera_OP_Grafica
public void Cabecera_OP_Grafica(string nomarchivo)
{
////// ClosedXML ////////
XLWorkbook oWB = new XLWorkbook(nomarchivo);
var oSheet = oWB.Worksheet(1);
switch (_Estado.ToUpper())
{
case "ORDENADO":
{
EmpresaDTO empresa = new DAO.EmpresaDAO().Read(1);
OrdenadoCabDTO miCabecera = (OrdenadoCabDTO)_Cabecera;
DTO.MediosPubDTO medio = CRUDHelper.Read(string.Format("IdentifMedio = '{0}'", _Espacio.IdentifMedio), BusinessMapper.GetDaoByEntity(BusinessMapper.eEntities.MediosPub));
string[] Meses = { "", "Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre" };
string aniomes = miCabecera.AnoMes.ToString();
oSheet.Cells("C6").Value = "" + Meses[Convert.ToInt32(aniomes.Substring(4, 2))].ToUpper() + "/" + aniomes.Substring(0, 4);
oSheet.Cells("C7").Value = medio.Name;
oSheet.Cells("C8").Value = _Espacio.Name;
oSheet.Cells("C9").Value = _Espacio.Telefono == null ? "" : _Espacio.Telefono;
oSheet.Cells("C10").Value = _Espacio.Contacto == null ? "" : _Espacio.Contacto.ToUpper();
oSheet.Cells("D14").Value = "MES: " + Meses[Convert.ToInt32(aniomes.Substring(4, 2))].ToUpper() + "/" + aniomes.Substring(0, 4);
oSheet.Cells("F25").Value = _Espacio.Responsable == null ? "" : _Espacio.Responsable.ToUpper();
SetUpDTO setup = new SetUpDTO();
string sector = setup.Sector;
oSheet.Cells("F26").Value = sector;
oSheet.Cells("F27").Value = empresa.Name;
oSheet.Cells("F28").Value = empresa.Leyenda;
break;
}
case "ESTIMADO": {
EmpresaDTO empresa = new DAO.EmpresaDAO().Read(1);
EstimadoCabDTO miCabecera = (EstimadoCabDTO)_Cabecera;
DTO.MediosPubDTO medio = CRUDHelper.Read(string.Format("IdentifMedio = '{0}'", _Espacio.IdentifMedio), BusinessMapper.GetDaoByEntity(BusinessMapper.eEntities.MediosPub));
string[] Meses = { "", "Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre" };
string aniomes = miCabecera.AnoMes.ToString();
oSheet.Cells("C6").Value = "" + Meses[Convert.ToInt32(aniomes.Substring(4, 2))].ToUpper() + "/" + aniomes.Substring(0, 4);
oSheet.Cells("C7").Value = medio.Name;
oSheet.Cells("C8").Value = _Espacio.Name;
oSheet.Cells("C9").Value = _Espacio.Telefono == null ? "" : _Espacio.Telefono;
oSheet.Cells("C10").Value = _Espacio.Contacto == null ? "" : _Espacio.Contacto.ToUpper();
oSheet.Cells("D14").Value = "MES: " + Meses[Convert.ToInt32(aniomes.Substring(4, 2))].ToUpper() + "/" + aniomes.Substring(0, 4);
oSheet.Cells("F25").Value = _Espacio.Responsable == null ? "" : _Espacio.Responsable.ToUpper();
SetUpDTO setup = new SetUpDTO();
string sector = setup.Sector;
oSheet.Cells("F26").Value = sector;
oSheet.Cells("F27").Value = empresa.Name;
oSheet.Cells("F28").Value = empresa.Leyenda;
break; }
case "CERTIFICADO":
{
EmpresaDTO empresa = new DAO.EmpresaDAO().Read(1);
CertificadoCabDTO miCabecera = (CertificadoCabDTO)_Cabecera;
DTO.MediosPubDTO medio = CRUDHelper.Read(string.Format("IdentifMedio = '{0}'", _Espacio.IdentifMedio), BusinessMapper.GetDaoByEntity(BusinessMapper.eEntities.MediosPub));
string[] Meses = { "", "Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre" };
string aniomes = miCabecera.AnoMes.ToString();
oSheet.Cells("C6").Value = "" + Meses[Convert.ToInt32(aniomes.Substring(4, 2))].ToUpper() + "/" + aniomes.Substring(0, 4);
oSheet.Cells("C7").Value = medio.Name;
oSheet.Cells("C8").Value = _Espacio.Name;
oSheet.Cells("C9").Value = _Espacio.Telefono == null ? "" : _Espacio.Telefono;
oSheet.Cells("C10").Value = _Espacio.Contacto == null ? "" : _Espacio.Contacto.ToUpper();
oSheet.Cells("D14").Value = "MES: " + Meses[Convert.ToInt32(aniomes.Substring(4, 2))].ToUpper() + "/" + aniomes.Substring(0, 4);
oSheet.Cells("F25").Value = _Espacio.Responsable == null ? "" : _Espacio.Responsable.ToUpper();
SetUpDTO setup = new SetUpDTO();
string sector = setup.Sector;
oSheet.Cells("F26").Value = sector;
oSheet.Cells("F27").Value = empresa.Name;
oSheet.Cells("F28").Value = empresa.Leyenda;
break;
}
}
oWB.SaveAs(nomarchivo);
oWB.Dispose();
oSheet = null;
oWB = null;
GC.Collect();
}
示例4: make_efile
//.........这里部分代码省略.........
xdate = ii.ToString("00") + "/" + iii.ToString("00") + "/" + i.ToString("0000");
_loop = true;
//============================================================================================
xcol = 1;
worksheet.Cell(xrow, xcol).SetValue(Convert.ToDateTime(xdate).ToLongDateString());
worksheet.Cell(xrow, xcol).Style.Font.FontSize = 10;
worksheet.Cell(xrow, xcol).Style.Font.Bold = true;
worksheet.Cell(xrow, xcol).Style.Font.FontName = "Calibri";
worksheet.Cell(xrow, xcol).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Left;
worksheet.Range("A" + xrow + ":J" + xrow).Row(1).Merge();
worksheet.Range("A" + xrow + ":J" + xrow).Row(1).Style.Border.TopBorder = XLBorderStyleValues.Thin;
worksheet.Range("A" + xrow + ":J" + xrow).Row(1).Style.Border.BottomBorder = XLBorderStyleValues.Thin;
worksheet.Range("A" + xrow + ":J" + xrow).Row(1).Style.Border.LeftBorder = XLBorderStyleValues.Thin;
worksheet.Range("A" + xrow + ":J" + xrow).Row(1).Style.Border.RightBorder = XLBorderStyleValues.Thin;
xrow += 1;
xrow = ExcelReport.xstr_excelfile(worksheet, department_code, xdate, xrow);
xrow += 2;
}
}
}
else if (ii == t_date_month)
{
if (_loop == true)
{
for (int iii = 1; iii <= t_date_day; iii++)
{
xdate = ii.ToString("00") + "/" + iii.ToString("00") + "/" + i.ToString("0000");
_loop = true;
//============================================================================================
xcol = 1;
worksheet.Cell(xrow, xcol).SetValue(Convert.ToDateTime(xdate).ToLongDateString());
worksheet.Cell(xrow, xcol).Style.Font.FontSize = 10;
worksheet.Cell(xrow, xcol).Style.Font.Bold = true;
worksheet.Cell(xrow, xcol).Style.Font.FontName = "Calibri";
worksheet.Cell(xrow, xcol).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Left;
worksheet.Range("A" + xrow + ":J" + xrow).Row(1).Merge();
worksheet.Range("A" + xrow + ":J" + xrow).Row(1).Style.Border.TopBorder = XLBorderStyleValues.Thin;
worksheet.Range("A" + xrow + ":J" + xrow).Row(1).Style.Border.BottomBorder = XLBorderStyleValues.Thin;
worksheet.Range("A" + xrow + ":J" + xrow).Row(1).Style.Border.LeftBorder = XLBorderStyleValues.Thin;
worksheet.Range("A" + xrow + ":J" + xrow).Row(1).Style.Border.RightBorder = XLBorderStyleValues.Thin;
xrow += 1;
xrow = ExcelReport.xstr_excelfile(worksheet, department_code, xdate, xrow);
xrow += 2;
}
}
else
{
for (int iii = f_date_day; iii <= t_date_day; iii++)
{
xdate = ii.ToString("00") + "/" + iii.ToString("00") + "/" + i.ToString("0000");
_loop = true;
//============================================================================================
xcol = 1;
worksheet.Cell(xrow, xcol).SetValue(Convert.ToDateTime(xdate).ToLongDateString());
worksheet.Cell(xrow, xcol).Style.Font.FontSize = 10;
worksheet.Cell(xrow, xcol).Style.Font.Bold = true;
worksheet.Cell(xrow, xcol).Style.Font.FontName = "Calibri";
worksheet.Cell(xrow, xcol).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Left;
worksheet.Range("A" + xrow + ":J" + xrow).Row(1).Merge();
worksheet.Range("A" + xrow + ":J" + xrow).Row(1).Style.Border.TopBorder = XLBorderStyleValues.Thin;
worksheet.Range("A" + xrow + ":J" + xrow).Row(1).Style.Border.BottomBorder = XLBorderStyleValues.Thin;
worksheet.Range("A" + xrow + ":J" + xrow).Row(1).Style.Border.LeftBorder = XLBorderStyleValues.Thin;
worksheet.Range("A" + xrow + ":J" + xrow).Row(1).Style.Border.RightBorder = XLBorderStyleValues.Thin;
xrow += 1;
xrow = ExcelReport.xstr_excelfile(worksheet, department_code, xdate, xrow);
xrow += 2;
}
}
}
}
}
}
}
worksheet.Cell(xrow, 1).SetValue("****** End of File ******");
worksheet.Cell(xrow, 1).Style.Font.FontSize = 10;
worksheet.Cell(xrow, 1).Style.Font.FontName = "Calibri";
workbook.SaveAs(Server.MapPath("~\\pdf\\" + HttpContext.Current.Session["username"] + "\\") + filename);
worksheet.Dispose();
workbook.Dispose();
x = "Daily Time Record Generated...";
return x;
}
示例5: Detalle_OP_PNT_Salida
//.........这里部分代码省略.........
{
IdentifAvisos.Add(miDetalle[i].IdentifAviso);
break;
}
}
for (int i = 0; i <= IdentifAvisos.Count - 1; i++)
{
Fila++;
Columna = 3;
aviso = Business.Avisos.Read(string.Format("IdentifAviso = '{0}'", IdentifAvisos[i]));
oSheet.Cell(Fila, Columna).Value = aviso.EtiquetaProd;
DTO.PiezasArteDTO pieza = CRUDHelper.Read(string.Format("IdentifPieza = '{0}'", aviso.IdentifPieza),
BusinessMapper.GetDaoByEntity(BusinessMapper.eEntities.PiezasArte));
DTO.AnunInternosDTO ai = CRUDHelper.Read(string.Format("IdentifAnun = '{0}'", pieza.IdentifAnun),
BusinessMapper.GetDaoByEntity(BusinessMapper.eEntities.AnunInternos));
oSheet.Cell(Fila, Columna + 1).Value = ai.Name;
oSheet.Cell(Fila, Columna + 2).Value = aviso.Zocalo;
oSheet.Cell(Fila, Columna + 3).Value = aviso.NroIngesta;
int cantsal = 0;
for (int j = 0; j <= miDetalle.Count - 1; j++)
{
if (miDetalle[j].IdentifAviso == IdentifAvisos[i])
{
cantsal++;
}
}
oSheet.Cell(Fila, Columna + 4).Value = cantsal;
Columna = 9;
decimal CostoPorSalida = miDetalle[0].CostoOp / miDetalle.Count;
oSheet.Cell(Fila, Columna).Value = CostoPorSalida;
}
Fila += 7;
oSheet.Cell(Fila, Columna).Value = _Espacio.Responsable;
Fila++;
DAO.SetUpDAO STUP = new DAO.SetUpDAO();
SetUpDTO setup = STUP.Read(1);
string sector = setup.Sector;
oSheet.Cell(Fila, Columna).Value = sector;
Fila++;
EmpresaDTO empresa = new DAO.EmpresaDAO().Read(1);
oSheet.Cell(Fila, Columna).Value = empresa.Name;
// telefonos //
for (int i = 0; i <= IdentifAvisos.Count - 1; i++)
{
AvisosIdAtenDTO aia = CRUDHelper.Read(string.Format("IdentifAviso = '{0}'", IdentifAvisos[i]), BusinessMapper.GetDaoByEntity(BusinessMapper.eEntities.AvisosIdAten));
oSheet.Cell("E" + (Fila + i).ToString()).Value = "'" + aia.IdentifIdentAte;
}
//////////////
break;
}
Fila++;
}
break;
}
#endregion
}
oWB.SaveAs(nomarchivo);
oWB.Dispose();
oSheet = null;
oWB = null;
GC.Collect();
}
示例6: Cabecera_OP_Calendario_Descriptivo
//.........这里部分代码省略.........
case "ESTIMADO": {
EmpresaDTO empresa = new DAO.EmpresaDAO().Read(1);
EstimadoCabDTO miCabecera = (EstimadoCabDTO)_Cabecera;
DTO.MediosPubDTO medio = CRUDHelper.Read(string.Format("IdentifMedio = '{0}'", _Espacio.IdentifMedio), BusinessMapper.GetDaoByEntity(BusinessMapper.eEntities.MediosPub));
string[] Meses = { "", "Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre" };
string aniomes = miCabecera.AnoMes.ToString();
//ARMADO DE CALENDARIO - MEJORAR
int mes = Convert.ToInt32(aniomes.Substring(4, 2));
int anio = Convert.ToInt32(aniomes.Substring(0, 4));
int DiasEnMes = System.DateTime.DaysInMonth(anio, mes);
string[] DiasSemana = { "", "Lunes", "Martes", "Miércoles", "Jueves", "Viernes", "Sábado", "Domingo" };
int PrimerDiaSemana = Convert.ToInt32(Convert.ToDateTime(aniomes.Substring(0, 4) + "-" + aniomes.Substring(4, 2) + "-" + "01").DayOfWeek);
int PrimerDiaMes = Convert.ToInt32(Convert.ToDateTime(aniomes.Substring(0, 4) + "-" + aniomes.Substring(4, 2) + "-" + "01").DayOfYear);
int dia = PrimerDiaMes - PrimerDiaSemana + 2;
for (int Filas = 20; Filas <= 40; Filas = Filas + 5)
{
for (int Columnas = 2; Columnas <= 8; Columnas++)
{
DateTime theDate = new DateTime(anio, 1, 1).AddDays(dia - 2);
oSheet.Cell(Filas, Columnas).Value = theDate;
dia++;
}
}
oSheet.Cells("C5").Value = "Orden de Publicidad - " + miCabecera.IdentifEspacio;
oSheet.Cells("B9").Value = miCabecera.PautaId;
oSheet.Cells("B10").Value = medio.Name;
oSheet.Cells("B11").Value = _Espacio.Name;
oSheet.Cells("B12").Value = "'" + Meses[Convert.ToInt32(aniomes.Substring(4, 2))].ToUpper() + "/" + aniomes.Substring(0, 4);
oSheet.Cells("B13").Value = _Espacio.Contacto == null ? "" : _Espacio.Contacto.ToUpper();
oSheet.Cells("A14").Value = "EMAIL: ";
oSheet.Cells("B14").Value = _Espacio.Email == null ? "" : _Espacio.Email;
FrecuenciaDTO frecuencia = CRUDHelper.Read(string.Format("IdentifFrecuencia = '{0}'", miCabecera.IdentifFrecuencia), BusinessMapper.GetDaoByEntity(BusinessMapper.eEntities.Frecuencia));
oSheet.Cells("B15").Value = frecuencia.Name + " de " + _Espacio.HoraInicio + " a " + _Espacio.HoraFin + "hs.";
break; }
case "CERTIFICADO": {
EmpresaDTO empresa = new DAO.EmpresaDAO().Read(1);
CertificadoCabDTO miCabecera = (CertificadoCabDTO)_Cabecera;
DTO.MediosPubDTO medio = CRUDHelper.Read(string.Format("IdentifMedio = '{0}'", _Espacio.IdentifMedio), BusinessMapper.GetDaoByEntity(BusinessMapper.eEntities.MediosPub));
string[] Meses = { "", "Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre" };
string aniomes = miCabecera.AnoMes.ToString();
//ARMADO DE CALENDARIO - MEJORAR
int mes = Convert.ToInt32(aniomes.Substring(4, 2));
int anio = Convert.ToInt32(aniomes.Substring(0, 4));
int DiasEnMes = System.DateTime.DaysInMonth(anio, mes);
string[] DiasSemana = { "", "Lunes", "Martes", "Miércoles", "Jueves", "Viernes", "Sábado", "Domingo" };
int PrimerDiaSemana = Convert.ToInt32(Convert.ToDateTime(aniomes.Substring(0, 4) + "-" + aniomes.Substring(4, 2) + "-" + "01").DayOfWeek);
int PrimerDiaMes = Convert.ToInt32(Convert.ToDateTime(aniomes.Substring(0, 4) + "-" + aniomes.Substring(4, 2) + "-" + "01").DayOfYear);
int dia = PrimerDiaMes - PrimerDiaSemana + 2;
for (int Filas = 20; Filas <= 40; Filas = Filas + 5)
{
for (int Columnas = 2; Columnas <= 8; Columnas++)
{
DateTime theDate = new DateTime(anio, 1, 1).AddDays(dia - 2);
oSheet.Cell(Filas, Columnas).Value = theDate;
dia++;
}
}
oSheet.Cells("C5").Value = "Orden de Publicidad - " + miCabecera.IdentifEspacio;
oSheet.Cells("B9").Value = miCabecera.PautaId;
oSheet.Cells("B10").Value = medio.Name;
oSheet.Cells("B11").Value = _Espacio.Name;
oSheet.Cells("B12").Value = "'" + Meses[Convert.ToInt32(aniomes.Substring(4, 2))].ToUpper() + "/" + aniomes.Substring(0, 4);
oSheet.Cells("B13").Value = _Espacio.Contacto == null ? "" : _Espacio.Contacto.ToUpper();
oSheet.Cells("A14").Value = "EMAIL: ";
oSheet.Cells("B14").Value = _Espacio.Email == null ? "" : _Espacio.Email;
FrecuenciaDTO frecuencia = CRUDHelper.Read(string.Format("IdentifFrecuencia = '{0}'", miCabecera.IdentifFrecuencia), BusinessMapper.GetDaoByEntity(BusinessMapper.eEntities.Frecuencia));
oSheet.Cells("B15").Value = frecuencia.Name + " de " + _Espacio.HoraInicio + " a " + _Espacio.HoraFin + "hs.";
break; }
}
oWB.SaveAs(nomarchivo);
oWB.Dispose();
oSheet = null;
oWB = null;
GC.Collect();
}
示例7: button_statis_outputExcel_Click
//.........这里部分代码省略.........
this.ShowMessage("正在创建 Excel 报表");
stop.Style = StopStyle.EnableHalfStop;
stop.OnStop += new StopEventHandler(this.DoStop);
stop.Initial("正在创建 Excel 报表 ...");
stop.BeginLoop();
EnableControls(false);
this.listView_baseList_records.Enabled = false;
this.listView_inventoryList_records.Enabled = false;
try
{
List<string> output_columns = StringUtil.SplitList(this.OutputColumns);
// return:
// -1 出错
// 0 放弃或中断
// 1 成功
nRet = CreateLostSheet(
stop,
doc,
output_columns,
out strError);
if (nRet != 1)
goto ERROR1;
// return:
// -1 出错
// 0 放弃或中断
// 1 成功
nRet = CreateOutOfRangeSheet(
stop,
doc,
output_columns,
out strError);
if (nRet != 1)
goto ERROR1;
// return:
// -1 出错
// 0 放弃或中断
// 1 成功
nRet = CreateBorrowedSheet(
stop,
doc,
output_columns,
out strError);
if (nRet != 1)
goto ERROR1;
// return:
// -1 出错
// 0 放弃或中断
// 1 成功
nRet = CreateVerifiedSheet(
stop,
doc,
output_columns,
out strError);
if (nRet != 1)
goto ERROR1;
}
finally
{
EnableControls(true);
this.listView_baseList_records.Enabled = true;
this.listView_inventoryList_records.Enabled = true;
stop.EndLoop();
stop.OnStop -= new StopEventHandler(this.DoStop);
stop.Initial("");
stop.HideProgress();
stop.Style = StopStyle.None;
if (doc != null)
{
doc.SaveAs(dlg.FileName);
doc.Dispose();
}
if (bLaunchExcel)
{
try
{
System.Diagnostics.Process.Start(dlg.FileName);
}
catch
{
}
}
}
this.ShowMessage("创建完成", "green", true);
return;
ERROR1:
// MessageBox.Show(this, strError);
this.ShowMessage(strError, "red", true);
}
示例8: Detalle_OP_Calendario_Numerico
//.........这里部分代码省略.........
else
{
STP[j] = Convert.ToInt32(oSheet.Cell(FilaPosicional, j + 2).Value);
}
STT[j] += STP[j];
}
}
FilaPosicional += 2;
for (int j = 1; j <= DiasEnMes; j++)
{
oSheet.Cell(FilaPosicional, j + 2).Value = STT[j];
}
////// LLENO MARGEN DERECHO CON TOTALES ////////////
FilaPosicional = 15;
decimal CostoTotal = 0;
decimal GrandTotal = 0;
int UnidadesTotales = 0;
for (int i = 0; i <= IdentifAvisos.Count - 1; i++)
{
FilaPosicional = FilaPosicional + 5;
for (int j = 0; j <= FilasProducto[i] - 1; j++)
{
oSheet.Cell("AH" + FilaPosicional.ToString()).FormulaA1 = string.Format("=SUM({0}{1}:{2}{3})", "C", FilaPosicional, "AG", FilaPosicional);
for (int k = 0; k <= miDetalle.Count - 1; k++)
{
if (miDetalle[k].IdentifAviso == IdentifAvisos[i])
{
oSheet.Cell("AI" + FilaPosicional.ToString()).Value = miDetalle[k].CostoOp;
oSheet.Cell("AJ" + FilaPosicional.ToString()).Value = miDetalle[k].Duracion;
oSheet.Cell("AK" + FilaPosicional.ToString()).Value = Convert.ToDecimal(oSheet.Cell("AH" + FilaPosicional.ToString()).Value) * Convert.ToDecimal(oSheet.Cell("AI" + FilaPosicional.ToString()).Value);
CostoTotal += Convert.ToDecimal(oSheet.Cell("AK" + FilaPosicional.ToString()).Value);
break;
}
}
oSheet.Cell("AK" + FilaPosicional.ToString()).Value = Convert.ToDecimal(oSheet.Cell("AH" + FilaPosicional.ToString()).Value) * Convert.ToDecimal(oSheet.Cell("AI" + FilaPosicional.ToString()).Value);
FilaPosicional++;
}
oSheet.Cell("AH" + FilaPosicional.ToString()).FormulaA1 = string.Format("=SUM({0}{1}:{2}{3})", "C", FilaPosicional, "AG", FilaPosicional);
oSheet.Cell("AI" + FilaPosicional.ToString()).Value = "";
oSheet.Cell("AJ" + FilaPosicional.ToString()).Value = "";
oSheet.Cell("AK" + FilaPosicional.ToString()).Value = CostoTotal;
GrandTotal += CostoTotal;
UnidadesTotales += Convert.ToInt32(oSheet.Cell("AH" + FilaPosicional.ToString()).Value);
CostoTotal = 0;
}
FilaPosicional += 2;
oSheet.Cell("AH" + FilaPosicional.ToString()).Value = UnidadesTotales;
oSheet.Cell("AK" + FilaPosicional.ToString()).Value = GrandTotal;
FilaPosicional += 3;
oSheet.Cell("AI" + FilaPosicional.ToString()).Value = _Espacio.Responsable;
DAO.SetUpDAO STUP = new DAO.SetUpDAO();
SetUpDTO setup = STUP.Read(1);
oSheet.Cell("AI" + (FilaPosicional + 1).ToString()).Value = setup.Sector;
EmpresaDTO empresa = new DAO.EmpresaDAO().Read(1);
oSheet.Cell("AI" + (FilaPosicional + 2).ToString()).Value = empresa.Name;
////////////////////////////////////////////////////
break;
}
}
/////////////////
oWB.SaveAs(nomArchivo);
oWB.Dispose();
oSheet = null;
oWB = null;
GC.Collect();
}
示例9: CreateReaderDetailExcelFile
//.........这里部分代码省略.........
// summary_loader.RecPaths = biblio_recpaths;
// 输出借阅历史表格
// 可能会抛出异常,例如权限不够
OutputBorrowHistory(sheet,
dom,
history_loader,
// this.MainForm.GetBiblioSummary,
summary_loader,
ref nRowIndex,
ref column_max_chars);
}
catch (Exception ex)
{
string strErrorText = "输出借阅历史时出现异常: " + ex.Message;
throw new Exception(strErrorText);
}
}
nRowIndex++; // 读者之间的空行
nReaderIndex++;
return true;
},
out strError);
if (nRet == -1)
return -1;
{
if (stop != null)
stop.SetMessage("正在调整列宽度 ...");
Application.DoEvents();
//double char_width = GetAverageCharPixelWidth(list);
// 字符数太多的列不要做 width auto adjust
foreach (IXLColumn column in sheet.Columns())
{
int MAX_CHARS = 50; // 60
int nIndex = column.FirstCell().Address.ColumnNumber - 1;
if (nIndex >= column_max_chars.Count)
break;
int nChars = column_max_chars[nIndex];
if (nIndex == 1)
{
column.Width = 10;
continue;
}
if (nIndex == 3)
MAX_CHARS = 50;
else
MAX_CHARS = 24;
if (nChars < MAX_CHARS)
column.AdjustToContents();
else
column.Width = Math.Min(MAX_CHARS, nChars);
//else
// column.Width = (double)list.Columns[i].Width / char_width; // Math.Min(MAX_CHARS, nChars);
}
}
this.ShowMessage("共导出读者记录 " + nReaderIndex + " 个", "green", true);
}
catch (Exception ex)
{
strError = "CreateDetailExcelFile() 出现异常: " + ExceptionUtil.GetExceptionText(ex);
return -1;
}
finally
{
if (stop != null)
stop.SetMessage("");
if (doc != null)
{
doc.SaveAs(dlg.FileName);
doc.Dispose();
}
if (bLaunchExcel)
{
try
{
System.Diagnostics.Process.Start(dlg.FileName);
}
catch
{
}
}
}
// TODO: sheet 可以按照单位来区分。例如按照班级
return 1;
}
示例10: CreateReaderDetailExcelFile
//.........这里部分代码省略.........
}
//
//
OutputReaderInfo(sheet,
dom,
nReaderIndex,
ref nRowIndex,
ref column_max_chars);
// 输出在借册表格
OutputBorrows(sheet,
dom,
ref nRowIndex,
ref column_max_chars);
// 输出违约金表格
OutputOverdues(sheet,
dom,
ref nRowIndex,
ref column_max_chars);
nRowIndex++; // 读者之间的空行
nReaderIndex++;
if (stop != null)
stop.SetProgressValue(nReaderIndex);
}
{
if (stop != null)
stop.SetMessage("正在调整列宽度 ...");
Application.DoEvents();
//double char_width = GetAverageCharPixelWidth(list);
// 字符数太多的列不要做 width auto adjust
foreach (IXLColumn column in sheet.Columns())
{
int MAX_CHARS = 50; // 60
int nIndex = column.FirstCell().Address.ColumnNumber - 1;
if (nIndex >= column_max_chars.Count)
break;
int nChars = column_max_chars[nIndex];
if (nIndex == 1)
{
column.Width = 10;
continue;
}
if (nIndex == 3)
MAX_CHARS = 50;
else
MAX_CHARS = 24;
if (nChars < MAX_CHARS)
column.AdjustToContents();
else
column.Width = Math.Min(MAX_CHARS, nChars);
//else
// column.Width = (double)list.Columns[i].Width / char_width; // Math.Min(MAX_CHARS, nChars);
}
}
}
finally
{
EnableControls(true);
this.listView_records.Enabled = true;
stop.EndLoop();
stop.OnStop -= new StopEventHandler(this.DoStop);
stop.Initial("");
stop.HideProgress();
stop.Style = StopStyle.None;
if (doc != null)
{
doc.SaveAs(dlg.FileName);
doc.Dispose();
}
if (bLaunchExcel)
{
try
{
System.Diagnostics.Process.Start(dlg.FileName);
}
catch
{
}
}
}
return 0;
}
示例11: ExportExcelEventHandler
/// <summary>
/// Exports the excel event handler.
/// </summary>
/// <param name="context">The context.</param>
private void ExportExcelEventHandler(ControllerContext context)
{
try
{
var workbook = new XLWorkbook();
if (this.ExportData != null)
{
context.HttpContext.Response.Clear();
// 編碼
context.HttpContext.Response.ContentEncoding = Encoding.UTF8;
// 設定網頁ContentType
context.HttpContext.Response.ContentType =
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
// 匯出檔名
var browser = context.HttpContext.Request.Browser.Browser;
var exportFileName = browser.Equals("Firefox", StringComparison.OrdinalIgnoreCase)
? this.FileName
: HttpUtility.UrlEncode(this.FileName, Encoding.UTF8);
context.HttpContext.Response.AddHeader(
"Content-Disposition",
string.Format("attachment;filename={0}", exportFileName));
// Add all DataTables in the DataSet as a worksheets
workbook.Worksheets.Add(this.ExportData, this.SheetName);
using (var memoryStream = new MemoryStream())
{
workbook.SaveAs(memoryStream);
memoryStream.WriteTo(context.HttpContext.Response.OutputStream);
memoryStream.Close();
}
}
workbook.Dispose();
}
catch (Exception ex)
{
throw;
}
}
示例12: CreateSummaryTable
private static void CreateSummaryTable(IXLCell scr)
{
XLWorkbook template = new XLWorkbook(Application.StartupPath + Helper.GetTemplateFileName());
var sheet = template.Worksheet("Template");
var summaryTableRange = sheet.Range(237, 8, 242, 17);
summaryTableRange.CopyTo(scr);
template.Dispose();
}
示例13: XLWorkbook
private void WriteOutStatusTaggedGenderExcel
(WordUp.DataSelection dataSelection, string outputFileName)
{
XLWorkbook workBook = new XLWorkbook();
IXLWorksheet dataSelectionWorkSheet = workBook.Worksheets.Add($"{dataSelection}");
workBook.SaveAs(new FileStream(outputFileName, FileMode.Create,
FileAccess.Write, FileShare.ReadWrite));
workBook.Dispose();
}
示例14: Detalle_OP_Calendario_Descriptivo
//.........这里部分代码省略.........
oSheet.Row(31).InsertRowsBelow(Horarios.Count - 1);
oSheet.Row(26).InsertRowsBelow(Horarios.Count - 1);
oSheet.Row(21).InsertRowsBelow(Horarios.Count - 1);
}
int FilaBase = 21;
for (int j = 1; j <= 5; j++) //semanas
{
for (int k = 2; k <= 8; k++) //columnas
{
oSheet.Cell(FilaBase + Horarios.Count, k).FormulaA1 = string.Format("=COUNTA({0}{1}:{2}{3})", Celdas[k].ToString(), (FilaBase).ToString(), Celdas[k].ToString(), (FilaBase + Horarios.Count - 1).ToString());
}
FilaBase += 5 + Horarios.Count - 1;
}
int anio = Convert.ToInt32(miCabecera.AnoMes.ToString().Substring(0, 4));
int mes = Convert.ToInt32(miCabecera.AnoMes.ToString().Substring(4, 2));
int DiasEnMes = System.DateTime.DaysInMonth(anio, mes);
for (int x = 0; x <= 4; x++)
{
FilaBase = 20 + (5 * x);
FilaBase += ((Horarios.Count - 1) * x) + 1;
for (int i = 0; i <= Horarios.Count - 1; i++)
{
oSheet.Cell(FilaBase + i, 1).Value = Horarios[i].ToString();
}
for (int i = 2; i <= 8; i++)
{
string DiaAnio = oSheet.Cell(FilaBase - 1, i).Value.ToString();
for (int j = 0; j <= miDetalle.Count - 1; j++)
{
if (miDetalle[j].Fecha.ToString() == DiaAnio)
{
for (int k = 0; k <= Horarios.Count - 1; k++)
{
if (miDetalle[j].Hora.ToString() == oSheet.Cell(FilaBase + k, 1).Value.ToString())
{
aviso = Business.Avisos.Read(string.Format("IdentifAviso = '{0}'", miDetalle[j].IdentifAviso));
oSheet.Cell(FilaBase + k, i).Value = aviso.EtiquetaProd;
break;
}
}
}
}
}
decimal CosOp = 0;
for (int i = 0; i <= miDetalle.Count - 1; i++)
{
CosOp += miDetalle[i].CostoOp;
}
int CeldaCosOp = 48 + ((Horarios.Count - 1) * 5);
oSheet.Cells("H" + CeldaCosOp.ToString()).Value = CosOp;
////firma//
oSheet.Cells("H" + (CeldaCosOp + 5).ToString()).Value = _Espacio.Responsable;
DAO.SetUpDAO STUP = new DAO.SetUpDAO();
SetUpDTO setup = STUP.Read(1);
oSheet.Cells("H" + (CeldaCosOp + 6).ToString()).Value = setup.Sector;
EmpresaDTO empresa = new DAO.EmpresaDAO().Read(1);
oSheet.Cells("H" + (CeldaCosOp + 7).ToString()).Value = empresa.Name;
oSheet.Name = "O" + aniomes + miCabecera.IdentifEspacio;
}
break;
}
#endregion
}
oWB.SaveAs(nomArchivo);
oWB.Dispose();
oSheet = null;
oWB = null;
GC.Collect();
}
示例15: WriteOutZustaendigAGOrtsTeilOrt
private void WriteOutZustaendigAGOrtsTeilOrt(ZustaendigAgOrtsTeilOrt ZustaendigAgOrtsTeilOrtInstance,
StatistikRootClass.StatistikDataSelectionTypes writeOutType, string OutputFileName)
{
XLWorkbook workBook = new XLWorkbook();
IXLWorksheet workSheetOhneOrte = workBook.Worksheets.Add(writeOutType.ToString());
WriteOutZustaendigAGOrtsTeilOrt(ZustaendigAgOrtsTeilOrtInstance,
writeOutType, workSheetOhneOrte, false);
IXLWorksheet workSheetMitOrte = workBook.Worksheets.Add(writeOutType + "_inclOrte");
WriteOutZustaendigAGOrtsTeilOrt(ZustaendigAgOrtsTeilOrtInstance,
writeOutType, workSheetMitOrte, true);
workBook.SaveAs(new FileStream(OutputFileName, FileMode.Create,
FileAccess.Write, FileShare.ReadWrite));
workBook.Dispose();
}