XML - espacios en blanco xml

 
Vista:
Imágen de perfil de erik

espacios en blanco xml

Publicado por erik (2 intervenciones) el 16/01/2014 23:15:40
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;
using System.IO;
using System.Collections;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using SifActivoFijo.Models;
using DocumentFormat.OpenXml.Spreadsheet;
using DocumentFormat.OpenXml.Packaging;

namespace SifActivoFijo.Controllers
{
public class ProcesaXML
{
static readonly CultureInfo Culture = new CultureInfo("en-US");

public ProcesaXML(Worksheet worksheet, SharedStringTable st, int tipo)
{
ObtenerActivos(worksheet, st, tipo);
}

public static void ObtenerActivos(Worksheet worksheet, SharedStringTable st, int tipo)
{
if (tipo == 1)
{
var results = new List<AF_ActivoFijo>();
var resulUbicacion = new List<AF_UbicacionActivoFijo>();
var dataRows = from row in worksheet.Descendants<Row>()
where row.RowIndex > 1
select row;

foreach (var row in dataRows)
{
var textValues = new List<string>();
foreach (var cell in from cell in row.Descendants<Cell>() where cell.CellValue != null select cell)
{
if (cell.DataType != null && cell.DataType.HasValue && cell.DataType == CellValues.SharedString)
{
textValues.Add(st.ChildElements[int.Parse(cell.CellValue.InnerText)].InnerText);
Console.WriteLine(cell.CellValue.InnerText);
}

else
textValues.Add(cell.CellValue.InnerText);
}
var textArray = textValues.ToList();
if (textArray.Count() <= 0) continue;

AF_ActivoFijo activosFijos = new AF_ActivoFijo
{
CodigoActivoFijo = textArray[0],
DescripcionActivoFijo = textArray[1],
AF_GrupoActivoFijo_CodigoGrupoAF = textArray[2],
GN_Portafolio_CodigoPortafolio = textArray[3],
Serial = textArray[4],
Costo = float.Parse(textArray[5]),
PorcentajeMargen = double.Parse(textArray[6], Culture),
CostoActivo = double.Parse(textArray[7], Culture),
ValorIva = float.Parse(textArray[8]),
SenDepreciable = convertir(textArray[9]),
SenDepreciacionIndividual = convertir(textArray[10]),
SenConfigurable = convertir(textArray[11]),
TiempoDepreciacionFiscal = Int32.Parse(textArray[12], NumberStyles.Integer, Culture),
TiempoDepreciacionContable = Int32.Parse(textArray[13], NumberStyles.Integer, Culture),
SaldoAdepreciarFiscal = double.Parse(textArray[14], Culture),
SaldoADepreciar = double.Parse(textArray[15], Culture),
FechaActivacion = Convert.ToDateTime((string)textArray[16]),
AF_GrupoContableAF_CodigoGrupoContableAF = textArray[17],
ST_Estado_CodigoEstado = textArray[18],
GN_Persona_CodigoPersona = textArray[19]
};

var ubicacionActivos = new AF_UbicacionActivoFijo
{
AF_ActivoFijo_CodigoActivoFijo = textArray[0],
GN_CentroDeCosto_CodigoCentroDeCosto = textArray[20],
GN_Persona_CodigoPersona = textArray[21],
GN_Nivel3_CodigoNivel3 = textArray[22],
Contacto = textArray[23],
Direccion = textArray[24],
Telefono = textArray[25],
Celular = textArray[26],
Email = textArray[27],
Responsable = textArray[28],
Responsable_documento = textArray[29],
Responsable_Telefono = textArray[30],
Sucursal = textArray[31],
NoContrato = textArray[32],
FechaInicial = Convert.ToDateTime((string)textArray[33])

};
results.Add(activosFijos);
resulUbicacion.Add(ubicacionActivos);
}

for (int i = 0; i < results.Count(); i++)
{
ActivoFijoController act = new ActivoFijoController();
act.InsertaMultiples(results[i], resulUbicacion[i]);
}
}
else {

var results = new List<AF_RevaluacionNIIF>();
var dataRows = from row in worksheet.Descendants<Row>()
where row.RowIndex > 1
select row;

foreach (var row in dataRows)
{

var textValues = new List<string>();
foreach (var cell in from cell in row.Descendants<Cell>() where cell.CellValue != null select cell)
{

if (cell.DataType != null && cell.DataType.HasValue && cell.DataType == CellValues.SharedString)
{
textValues.Add(st.ChildElements[int.Parse(cell.CellValue.InnerText)].InnerText);
Console.WriteLine(cell.CellValue.InnerText);
}

else
textValues.Add(cell.CellValue.InnerText);
}
var textArray = textValues.ToList();
if (textArray.Count() <= 0) continue;



AF_RevaluacionNIIF activosFijos = new AF_RevaluacionNIIF
{
CodigoActivoFijo = textArray[0],
fechaRevaluacion = Convert.ToDateTime(textArray[1]),
CodigoCentroCosto = textArray[2],
valorRazonable = double.Parse(textArray[3]),
valorResidual = double.Parse(textArray[4]),
valorDeterioro = double.Parse(textArray[5]),
valorDeRevaluacion = double.Parse(textArray[6]),
NuevaVidaUtilNIIF = Convert.ToInt32(textArray[7])
};


results.Add(activosFijos);

}
for (int i = 0; i < results.Count(); i++)
{
ReevaluacionNiifController act = new ReevaluacionNiifController();
act.InsertaMultiples(results[i]);
}
}
}

public static bool convertir(string val) {

if (val.Equals(1))
{
return true;
}
else {
return false;
}
}
}
}
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