Ver Mensaje Individual
  #2 (permalink)  
Antiguo 15/01/2009, 05:32
gerard_a
 
Fecha de Ingreso: septiembre-2007
Mensajes: 68
Antigüedad: 16 años, 7 meses
Puntos: 0
Respuesta: trabajar con varias hojas en un excel

Bueno he seguido en mi busqueda de información y he llegado a una posible solucion, construir el excel con StringWriter.

Actualmente tengo esta estructura:

Código:
<WorkSheet ss:Name="Seccion1">
<Table>
<Row>
<Cell ss:StyleID="s62"><Data ss:Type="String">Empleado</Data></Cell>
<Cell ss:StyleID="s62"><Data ss:Type="String">Dept</Data></Cell>
<Cell ss:StyleID="s62"><Data ss:Type="String">Categoria</Data></Cell>
</Row>
<Row>
<Cell><Data ss:Type="String">nombre 1</Data></Cell>
<Cell><Data ss:Type="String">dept 1/Data></Cell>
<Cell><Data ss:Type="String">cat. trabajador 1</Data></Cell>
</Row>
</Table>
</WorkSheet>
<WorkSheet ss:Name="Seccion2">
<Table>
<Row>
<Cell ss:StyleID="s62"><Data ss:Type="String">Empleado</Data></Cell>
<Cell ss:StyleID="s62"><Data ss:Type="String">Dept</Data></Cell>
<Cell ss:StyleID="s62"><Data ss:Type="String">Categoria</Data></Cell>
</Row>
<Row>
<Cell><Data ss:Type="String">nombre 2</Data></Cell>
<Cell><Data ss:Type="String">dept 2/Data></Cell>
<Cell><Data ss:Type="String">cat. trabajador 2</Data></Cell>
</Row>
</Table>
</WorkSheet>
y le asigno esta cabecera:

Código:
StringBuilder sb = new StringBuilder(818);
            sb.AppendFormat(@"<?xml version=""1.0""?>{0}", Environment.NewLine);
            sb.AppendFormat(@"<?mso-application progid=""Excel.Sheet""?>{0}", Environment.NewLine);
            sb.AppendFormat(@"<Workbook xmlns=""urn:schemas-microsoft-com:office:spreadsheet""{0}", Environment.NewLine);
            sb.AppendFormat(@" xmlns:o=""urn:schemas-microsoft-com:office:office""{0}", Environment.NewLine);
            sb.AppendFormat(@" xmlns:x=""urn:schemas-microsoft-com:office:excel""{0}", Environment.NewLine);
            sb.AppendFormat(@" xmlns:ss=""urn:schemas-microsoft-com:office:spreadsheet""{0}", Environment.NewLine);
            sb.AppendFormat(@" xmlns:html=""http://www.w3.org/TR/REC-html40"">{0}", Environment.NewLine);
            sb.AppendFormat(@" <Styles>{0}", Environment.NewLine);
            sb.AppendFormat(@"  <Style ss:ID=""Default"" ss:Name=""Normal"">{0}", Environment.NewLine);
            sb.AppendFormat(@"   <Alignment ss:Vertical=""Bottom""/>{0}", Environment.NewLine);
            sb.AppendFormat(@"   <Borders/>{0}", Environment.NewLine);
            sb.AppendFormat(@"   <Font ss:FontName=""Calibri"" x:Family=""Swiss"" ss:Size=""11"" ss:Color=""#000000""/>{0}", Environment.NewLine);
            sb.AppendFormat(@"   <Interior/>{0}", Environment.NewLine);
            sb.AppendFormat(@"   <NumberFormat/>{0}", Environment.NewLine);
            sb.AppendFormat(@"   <Protection/>{0}", Environment.NewLine);
            sb.AppendFormat(@"  </Style>{0}", Environment.NewLine);
            sb.AppendFormat(@"  <Style ss:ID=""s62"">{0}", Environment.NewLine);
            sb.AppendFormat(@"   <Font ss:FontName=""Calibri"" x:Family=""Swiss"" ss:Size=""11"" ss:Color=""#000000""{0}", Environment.NewLine);
            sb.AppendFormat(@"    ss:Bold=""1""/>{0}", Environment.NewLine);
            sb.AppendFormat(@"  </Style>{0}", Environment.NewLine);
            sb.AppendFormat(@"  <Style ss:ID=""s63"">{0}", Environment.NewLine);
            sb.AppendFormat(@"   <NumberFormat ss:Format=""Short Date""/>{0}", Environment.NewLine);
            sb.AppendFormat(@"  </Style>{0}", Environment.NewLine);
            sb.AppendFormat(@" </Styles>{0}", Environment.NewLine);
            sb.Append(@"{0}</Workbook>");
            return sb.ToString();
Me pone bien el nombre de la celda en la primera hoja pero no me crea la segunda hoja, ya que lo añade todo en la primera y ademas pone el contenido que figura en cada WorkSheet dentro de la primera celda de cada columna, es decir, en la celda 1-1 me pone el todo el contenido del worksheet Seccion1
y en la celda 2-1 me pone el contenido del worksheet Seccion2

Sabeis porque ocurre esto?

Un saludo