XML - Como llenar espacios en blanco cuando envio un archivo con c#?

 
Vista:
Imágen de perfil de erik puentes

Como llenar espacios en blanco cuando envio un archivo con c#?

Publicado por erik puentes (2 intervenciones) el 15/01/2014 17:08:08
Buenas Tardes

Tengo una duda::: Cuando cargo el archivo de Excel lo carga bien. pero cuando le doy enviar. me aparece este error :Referencia a objeto no establecida como instancia de un objeto. la línea es string sheetId = workSheets.FirstOrDefault(s => s.Name == @"ActivosFijos").Id;


Este error creo que aparece cuando los datos se corren al lado izquiero cuando hay espacios en blanco en la columna y se desordenan los datos ya que son de diferentes tipos.

dejo el código

using System.Web;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Spreadsheet;
using System.IO;
using System.IO.Packaging;
using System.Linq;
using System;
using System.Web.Mvc;
using SifActivoFijo.Models;
using System.Data.Entity.Validation;
using System.Text;
using System.Collections;
using System.Xml.Linq;



namespace SifActivoFijo.Controllers
{
public class ProcesarExcel
{
string libroRuta;
private SIFACTIVOFIJOEntities db = new SIFACTIVOFIJOEntities();


public ProcesarExcel(string ws, int tipo)
{
libroRuta = HttpContext.Current.Server.MapPath(ws);

ReadExcelFileDOM(libroRuta, tipo);
}

public void ReadExcelFileDOM(string fileName, int tipo)
{
if(tipo==1)

{
using (SpreadsheetDocument document = SpreadsheetDocument.Open(fileName,true))
{

var workbook = document.WorkbookPart.Workbook;
var workSheets = workbook.Descendants<Sheet>();

string sheetId = workSheets.FirstOrDefault(s => s.Name == @"ActivosFijos").Id;
var sheets =(WorksheetPart)document.WorkbookPart.GetPartById(sheetId);

var sharedStringTable = document.WorkbookPart.SharedStringTablePart.SharedStringTable;
ProcesaXML pex = new ProcesaXML(sheets.Worksheet, sharedStringTable, tipo);
}
}
else {
using (SpreadsheetDocument document = SpreadsheetDocument.Open(fileName, true))
{

var workbook = document.WorkbookPart.Workbook;
var workSheets = workbook.Descendants<Sheet>();

string sheetId = workSheets.FirstOrDefault(s => s.Name == @"Activos a reevaluar").Id;
var sheets = (WorksheetPart)document.WorkbookPart.GetPartById(sheetId);

var sharedStringTable = document.WorkbookPart.SharedStringTablePart.SharedStringTable;
ProcesaXML pex = new ProcesaXML(sheets.Worksheet, sharedStringTable, tipo);
}
}
}

}
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder