|
IWorksheet worksheet = workbook.Worksheets[0];
int lastRow = worksheet.Range.LastRow;
(or) int lastRow1 = worksheet.UsedRange.LastRow; |
|
int lastRow2 = worksheet.Rows.Length; |
|
Query |
Response | |
|
can you check the specific results for me?
I have compared the result from lastrow and the result from the vba code, and the result from vba is 21 while lastrow is 34 for the first sheet. |
For the given file, XlsIO returns last row index as 34 equivalent to Microsoft Excel’s “Ctrl+End” behavior, which considers the used blank cells too. You can get the last row index (equivalent to “Ctrl+DownArrow”) without considering the blank cells by setting the UsedRangeIncludesFormatting property to false as below.
Code snippet:
After setting this property to false, you can get the following results with the suggested properties to get the index of last row.
Kindly let us know if this helps.
| |
|
i have 2nd question with merge files
Notes: I will ignore the header from file2, however
although I chose exportRangecopyoption = all
file merge results that I get
from row22, my rows does not contain format
Please check this! |
With the shared information, we have reproduced the mentioned issue with the below code and validating it currently. We will share the validation details on August 31st, 2020.
Code snippet:
Please confirm us whether you are also facing the issue while copying using CopyTo method as highlighted.
|
|
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
IWorkbook workbook = application.Workbooks.Open("Block P1.xlsx");
IWorksheet destinationSheet = workbook.Worksheets[0];
destinationSheet.UsedRangeIncludesFormatting = false;
int lastRow = destinationSheet.Rows.Length;
IWorkbook workbook1 = application.Workbooks.Open("Block P2.xlsx");
IWorksheet sourceSheet = workbook1.Worksheets[0];
int endRow = sourceSheet.Rows.Length;
int endColumn = sourceSheet.Columns.Length;
IRange sourceRange = sourceSheet[2, 1, endRow, endColumn];
int destinationRowIndex = lastRow + 1;
IRange destinationRange = destinationSheet[destinationRowIndex, 1, lastRow + endRow - 1, endColumn];
sourceRange.CopyTo(destinationRange, ExcelCopyRangeOptions.All);
IRange range = destinationSheet[1, 1, destinationSheet.Rows.Length, endColumn];
IListObject listObject = destinationSheet.ListObjects[0];
listObject.Location = range;
workbook.SaveAs("Output1.xlsx");
} |
IWorkbook workbook = null;
foreach (string filepath in listpath)
{
if (workbook == null)
workbook = GetWorkbook(application, filepath);
else
{
IWorkbook temp = GetWorkbook(application, filepath );
workbook.Worksheets.AddCopy(temp.Worksheets, copyflagsoption);
temp.close(false);
}
}
savefile(....);Also I'd like to ask about ExcelWorksheetCopyFlags.CopyColumnHeight (Is the name wrong or not?)
|
Query |
Response |
|
Please check my code!
I didn't create a new workbook, I get first workbook and then added other worksheets to the first workbook and it got error. |
We are able to reproduce the issue when opening the first workbook and adding other worksheets to the first workbook. We will provide patch for the fix on October 19th, 2020.
Feedback link: https://www.syncfusion.com/feedback/18219/copying-multiple-worksheets-with-tables-leads-to-file-corruption
We appreciate your patience.
|
|
Also I'd like to ask about ExcelWorksheetCopyFlags.CopyColumnHeight (Is the name wrong or not?) |
The name ExcelWorksheetCopyFlags.CopyColumnHeight is correct. Kindly look into the following link for ExcelWorksheetCopyFlags enumeration.
|
|
foreach (IWorksheet worksheet in workbook2.Worksheets)
{
IRange range = worksheet.UsedRange;
for (int i = range.Row; i <= range.LastRow; i++)
{
for (int j = range.Column; j <= range.LastColumn; j++)
{
Color color = Color.FromArgb(worksheet[i, j].CellStyle.Color.A, worksheet[i, j].CellStyle.Color.R,
worksheet[i, j].CellStyle.Color.G, worksheet[i, j].CellStyle.Color.B);
if (color.Name != "ffffffff")
{
worksheet[i, j].CellStyle.Color = Color.Black;
worksheet[i, j].CellStyle.Color = color;
}
}
}
} |