Quantcast
Channel: ClosedXML - The easy way to OpenXML
Viewing all articles
Browse latest Browse all 1877

New Post: How to expand the Range of a Work Table?

$
0
0
Hi Team,

I have a work table in a worksheet that has items and being used by other worksheet, however the calculations are wrong since I am not able to extend range of the data table. Can somebody shed me some light using closedXML, as my only work around at the moment is use excel interop, Resize like this
var range = xlSheet.get_Range("A1", oMissing).get_Resize(xlListItem.ListRows.Count + 1, xlListItem.ListColumns.Count);
xlListItem.Resize(range);
var workbook = new clsXML.XLWorkbook(localPath);
var worksheet = workbook.Worksheet("Raw Metrics Data");
var worktable = worksheet.Table("MetricsLogging");

Console.WriteLine("Number of items in Excel at START: " + worktable.RowCount());
if (data.Count > 0)
{
       var lastrow = worktable.LastRow().Cell("F").Value; // Created Date
       DateTime lastUpdate = DateTime.Now.AddYears(-2); // Default Value, 2 years before last run
       if (lastrow.ToString().Length > 0)
              lastUpdate = (DateTime)lastrow;
       Console.WriteLine("Last Updated: " + lastUpdate.ToLongDateString());

       var metrics = from m in data where m.CreatedDate > lastUpdate orderby m.CreatedDate ascending select new { m.LogType, m.Category, m.Item, m.UDC, m.CreatedBy.LookupValue, m.CreatedDate, m.VisitingUrl.Url, region = m.CreatedBy.LookupValue.Substring(0, m.CreatedBy.LookupValue.IndexOf("\\")) };
        var tableWithData = worktable.Cell(worktable.RowCount() + 1, 1).InsertData(metrics.AsEnumerable()); // Insert the Data in Worksheet (not in worktable)


         workbook.SaveAs(localPath);

         Console.WriteLine("Number of items in Excel at END: " + worktable.RowCount());
}
Thanks in advance

Regards,
Wendel

Viewing all articles
Browse latest Browse all 1877

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>