im trying to populate an XLS template, and to test the best way im using the following code[code]using System;using ClosedXML.Excel;using System.Linq;using System.Diagnostics;namespace ClosedXML_Examples{ public class Program { static void Main(string[] args) { int innerloop = 100; Stopwatch s = new Stopwatch(); for (int k = 1; k <= 1; k++) // just to test Speed-slowdown when working with Large Data. raise values for testing { XLWorkbook workbook = new XLWorkbook(XLEventTracking.Disabled); s.Reset(); s.Start(); copyDown3(makeSheet(workbook, "copy_loop"), 1, innerloop, k); s.Stop(); Console.WriteLine(string.Format("copy1 : Zeit für {0:D5} durchläufe : {1} = {2:F2} ms/100", k * innerloop, s.Elapsed, (decimal)s.ElapsedMilliseconds / (k * innerloop) * 100)); workbook.SaveAs("test.xlsx"); } Console.Read(); } static IXLWorksheet makeSheet(XLWorkbook workbook,string name) { IXLWorksheet ws = workbook.Worksheets.Add(name); ws.Cell(2, 1).Value = "ende"; // zeile 1 vorbereiten ws.Cell(1, 1).Value = 1.123; for (int x = 1; x <= 21; x++) ws.Cell(1, x).Style.NumberFormat.Format = "#,##0.00"; for (int x = 0; x < 7; x++) { ws.Cell(1, 3 * x + 1).Value = 3 * x + 1; ws.Cell(1, 3 * x + 2).Value = 3 * x + 2; ws.Cell(1, 3 * x + 3).FormulaR1C1 = "=RC[-2]+RC[-1]"; ws.Cell(1, 3 * x + 3).Style.Fill.BackgroundColor = XLColor.Xanadu; } return ws; } static void copyDown3(IXLWorksheet ws, int srcrow, int innerloop, int anz) { for (int i = 0; i < innerloop * anz; i++) { ws.Row(srcrow).CopyTo(ws.Row(srcrow + 1 + i)); // <-- Format isnt copied ! . Why ? } } }}[/code]the formulas are copied, but the styles-Formats are getting lost.am i doing something wrong, or is it bugged ?
↧