Hello,
Hi Ashish,
var workbook = new Workbook(“D:/rangecells.xlsx”);
var sheet = workbook.Worksheets[0];
var cells = workbook.Worksheets[0].Cells;
var range = sheet.Cells.MaxDisplayRange;
sheet.Cells.ClearContents(range.FirstRow, range.FirstColumn, range.RowCount, range.ColumnCount);
workbook.Save(“D:/output.xlsx”);
Hello Babar raza,
Hi Ashish,
I gave predefined format in some rows of Input files and when output generates then it does not extend format in further rows. it should extend formatting till the end row.
Hello Babar raza,
Hi Ashish,
var workbook = new Workbook(“D:/InputTemplate.xlsx”);
var worksheet = workbook.Worksheets[“BuyerList”];
var cells = worksheet.Cells;
var table = worksheet.ListObjects[0] ;
//Adding 10 more rows to the table with formatting intact
table.Resize(table.StartRow, table.StartColumn, table.EndRow + 10, table.EndColumn, true);
workbook.Save(“D:/result.xlsx”);
Hello Babar Raza
if (table != null)
{
table.Resize(table.StartRow, table.StartColumn, cell.MaxDataRow, cell.MaxDataColumn, true);
}
Hi Ashish,
var book = new Workbook(“D:/inputtemplate.xlsm”);
Console.WriteLine("Number of worksheets: " + book.Worksheets.Count);
var sheet = book.Worksheets[“Pipeline”];
var listObjects = sheet.ListObjects;
var table = listObjects[0];
if (table != null)
{
Console.WriteLine("Number of rows in table: " + table.EndRow);
table.Resize(table.StartRow, table.StartColumn, table.EndRow + 10, table.EndColumn, true);
Console.WriteLine("Number of rows in table after resize: " + table.EndRow);
}
book.Save(“D:/result.xlsm”, SaveFormat.Xlsm);
Hello Babar Raza,
Hi Ashish,
Hello Babar Raza,
Hello Babar Raza,
I found the issue. Actually i was clearing worksheet data with following code before finding listobjects.
if (worksheet.Cells.Count > 0)
{
//worksheet.Cells.ClearContents(1, 0, worksheet.Cells.MaxDataRow, worksheet.Cells.MaxDataColumn);
var range = worksheet.Cells.MaxDisplayRange;
worksheet.Cells.ClearContents(range.FirstRow, range.FirstColumn, range.RowCount, range.ColumnCount);
}
var listObjects = worksheet.ListObjects;
var table = listObjects[0];
if (table != null)
{
table.Resize(table.StartRow, table.StartColumn, cell.MaxDataRow, cell.MaxDataColumn, true);
}
So after applying ClearContents code i am trying to find list object so it is not able to find as with clearing data it is also clearing table object as well in worksheet. how can i prevent to do that? what should be the work around on this?
Thanks & Regards
Ashish Rajguru
Hi Ashish,
Please note, you are clearing the MaxDisplayRange that will clear everything on the worksheet including the ListObjects . You can workaround this situation in two ways, that are as follow.
- While clearing the MaxDisplayRange , do not clear the ListObject’s header. It will retain the ListObject and it’s formatting.
- Do not clear the MaxDisplayRange , instead clear the ListObject’s data range.
Please check the below provided code snippet that uses the both above mentioned approaches where first approach is commented out at the moment. You may use one option at a time.
C#
var book = new Workbook(“D:/inputtemplate.xlsx”);
var worksheet = book.Worksheets[“BuyerList”];
var listObjects = worksheet.ListObjects;
var table = listObjects[0];
if (worksheet.Cells.Count > 0)
{
//var range = worksheet.Cells.MaxDisplayRange;
//worksheet.Cells.ClearContents(range.FirstRow + 1, range.FirstColumn, range.RowCount, range.ColumnCount);
var range = table.DataRange;
worksheet.Cells.ClearContents(range.FirstRow, range.FirstColumn, range.RowCount, range.ColumnCount);
}
book.Save(“D:/clearcontent.xlsx”);
if (table != null)
{
table.Resize(table.StartRow, table.StartColumn, table.EndRow + 10, table.EndColumn, true);
}
book.Save(“D:/output.xlsx”, SaveFormat.Xlsx);
Save Editcancel
<span class="kwrd">if</span> (table != <span class="kwrd">null</span>)
{
table.Resize(table.StartRow, table.StartColumn, table.EndRow + 10, table.EndColumn, <span class="kwrd">true</span>);
}
book.Save("D:/output.xlsx", SaveFormat.Xlsx);
Hi again,
Hello Babar Raza,
Hi Ashish,
Hi again,
Hi,
Please try our latest version/fix:
Your issue should be fixed in it.
Let us know your feedback.
Thank you.
The issues you have found earlier (filed as CELLSNET-43725) have been fixed in this update.
This message was posted using Notification2Forum from Downloads module by Aspose Notifier.