Hello,
Hi Ashish,
- Worksheet.Cells.MaxColumn //Max Column in a Worksheet
- Worksheet.Cells.MaxRow //Max Row in a Worksheet
- Worksheet.Cells.MaxDataColumn //Max Data Column in a Worksheet
- Worksheet.Cells.MaxDisplayRange //Max Data range in a worksheet
- Worksheet.Cells.MaxDataRow //Max Data Row in a Worksheet
- Worksheet.Cells.MinColumn
- Worksheet.Cells.MinRow
Hi,
Hi,
Thanks for your posting and using Aspose.Cells for .NET.
Please download and use the latest version:
Aspose.Cells for .NET (Latest Version)
Worksheet.Cells.MaxDisplayRange will serve the purpose. It will cover all the cells in your worksheet that has some data.
Your code will look like this
C#
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
Cells cell = worksheet.Cells;
//Create a new style adding to the workbook styles collection
Style style = workbook.Styles[workbook.Styles.Add()];
//Specify the style’s fill color
style.Font.IsBold = true;
//Create a styleflag object
StyleFlag styleFlag = new StyleFlag();
//Specify all attributes
styleFlag.All = true;
Range range = worksheet.Cells.MaxDisplayRange;
Hello,
Worksheet worksheet = workbook.Worksheets[0];
Cells cell = worksheet.Cells;
//Create a new style adding to the workbook styles collection
Style style = workbook.Styles[workbook.Styles.Add()];
//Specify the style’s fill color
style.Font.IsBold = true;
//Create a styleflag object
StyleFlag styleFlag = new StyleFlag();
//Specify all attributes
styleFlag.All = true;
//Range range = cell.CreateRange(“A3”, CellsHelper.CellIndexToName(cell.MaxDataRow, cell.MaxDataColumn));
Range range = worksheet.Cells.MaxDisplayRange;
cell[1, i].PutValue(headerText[i]);
Hi,
Thanks for your feedback.
Could you please provide us your sample source xls/xlsx file and the expected output xls/xlsx file? You can create both of them manually using Ms-Excel 2010 and attach here.
It will help us see your problem and we will provide you a sample code accordingly.
Hi Ashish,
You can get the ending cell of a row using LastCell parameter of the row object. For example, considering that Row 0 is your header row, you can write your statements like:
Workbook workbook = new Workbook(“K://temp.xls”);
//Get the Cells Collection object
Cells cells = workbook.Worksheets[0].Cells;
//Get the last cell in the Row
Cell cell = cells.Rows[0].LastCell;
//Create Range
Range range = cells.CreateRange(“A1”, cell.Name);
I hope this gives what you want.
Hello,
Hello Kashif,
Worksheet worksheet = workbook.Worksheets[0];
Cells cell = worksheet.Cells;
Cell lastcell = cell.Rows[2].LastCell;
Hi,
Workbook workbook = new Workbook("K://SampleSourceFile.xlsx");Cells cells = workbook.Worksheets[0].Cells;Cell cellA3 = cells["A3"];int iHeaderRow = cellA3.Row;Cell LastCell = cells.Rows[iHeaderRow].LastCell;Range range = cells.CreateRange(cellA3.Name, LastCell.Name);//Create a new style adding to the workbook styles collectionStyle style = workbook.Styles[workbook.Styles.Add()];//Specify the style's fill colorstyle.Font.IsBold = true;//Create a styleflag objectStyleFlag styleFlag = new StyleFlag();//Specify all attributesstyleFlag.All = true;range.ApplyStyle(style, styleFlag);workbook.Save("K://SampleSourceFileOut.xlsx");
Hi,
Cells cell = worksheet.Cells;
Cell lastcell = cell.Rows[2].LastCell;
Hi Ashish,
Also, the same is true for ranges that don't have pre-existing data. You canWorkbook workbook = new Workbook();//Get the Cells Collection objectCells cells = workbook.Worksheets[0].Cells;Column col = cells.Columns[0];Style style = workbook.Styles[workbook.Styles.Add()];style.Font.IsBold = true;//Create a styleflag objectStyleFlag styleFlag = new StyleFlag();//Specify all attributesstyleFlag.All = true;col.ApplyStyle(style, styleFlag);cells["A1"].PutValue("Hello");workbook.Save("K://output.xls");