This commit is contained in:
116
General/ExcelToBD.aspx.cs
Normal file
116
General/ExcelToBD.aspx.cs
Normal file
@@ -0,0 +1,116 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
using ClosedXML.Excel;
|
||||
using Extensiones;
|
||||
|
||||
public partial class General_ExcelToBD : System.Web.UI.Page
|
||||
{
|
||||
#region propiedades
|
||||
|
||||
private string URLFile
|
||||
{
|
||||
get
|
||||
{
|
||||
if (ViewState["URLFile"] == null) { return ""; }
|
||||
else { return ViewState["URLFile"].ToString(); }
|
||||
}
|
||||
|
||||
set { ViewState["URLFile"] = value; }
|
||||
}
|
||||
private string extension
|
||||
{
|
||||
get
|
||||
{
|
||||
if (ViewState["extension"] == null) { return ""; }
|
||||
else { return ViewState["extension"].ToString(); }
|
||||
}
|
||||
|
||||
set { ViewState["extension"] = value; }
|
||||
}
|
||||
private List<ADSWorksBooks> workBooks
|
||||
{
|
||||
get
|
||||
{
|
||||
if (ViewState["workBooks"] == null) { return null; }
|
||||
else { return (List<ADSWorksBooks>)ViewState["workBooks"]; }
|
||||
}
|
||||
|
||||
set { ViewState["workBooks"] = value; }
|
||||
}
|
||||
#endregion
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected void LnkCargarArchivo_Click(object sender, EventArgs e)
|
||||
{
|
||||
List<Archivo> filesgral = TxtArchivoXls.getfiles().Archivos;
|
||||
workBooks = new List<ADSWorksBooks>();
|
||||
foreach (Archivo fileItem in filesgral)
|
||||
{
|
||||
extension = System.IO.Path.GetExtension(string.Format(@"{0}Temp\{1}", AppDomain.CurrentDomain.BaseDirectory, fileItem.filename)).Replace(".", "");
|
||||
URLFile = fileItem.FileUrl;
|
||||
}
|
||||
using (var workbook = new XLWorkbook(URLFile))
|
||||
{
|
||||
int position = 1;
|
||||
foreach (IXLWorksheet wokitem in workbook.Worksheets)
|
||||
{
|
||||
workBooks.Add(new ADSWorksBooks() { Name = wokitem.Name, position = position++ });
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
DdlWorkBooks.DataSource = workBooks;
|
||||
DdlWorkBooks.DataBind();
|
||||
if (workBooks.Count > 0)
|
||||
{
|
||||
DdlWorkBooks.SelectedIndex = 0;
|
||||
DdlWorkBooks_SelectedIndexChanged(null,null);
|
||||
}
|
||||
}
|
||||
|
||||
protected void DdlWorkBooks_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
using (var workbook = new XLWorkbook(URLFile))
|
||||
{
|
||||
|
||||
int Filas = 0;
|
||||
int columnas = 0;
|
||||
IXLWorksheet workSheet = workbook.Worksheet(DdlWorkBooks.SelectedValue.ToEntero());
|
||||
Filas = workSheet.LastColumnUsed().CellCount();
|
||||
columnas = workSheet.LastRowUsed().CellCount();
|
||||
TxtFilas.Text = Filas.ToString();
|
||||
TxtInicia.Text = "1";
|
||||
TxtColumnas.Text = Filas.ToString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void Lnkdoit_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected void LnkContinuar_Click(object sender, EventArgs e)
|
||||
{
|
||||
int Filas = 0;
|
||||
int columnas = 0;
|
||||
using (var workbook = new XLWorkbook(URLFile))
|
||||
{
|
||||
IXLWorksheet workSheet = workbook.Worksheet(DdlWorkBooks.SelectedValue.ToEntero());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class ADSWorksBooks
|
||||
{
|
||||
public int position { get; set; }
|
||||
public string Name { get; set; }
|
||||
}
|
||||
Reference in New Issue
Block a user