Free Support Forum - aspose.com

How do I format data while I export to Excel

Hi,

I wanted a help with copying only formatting from a row to max data rows and columns.

I have a static formatting for a single row in a template, my requirement is to when the data gets imported to the excel I want to copy the formatting which is placed static in a top row to all the rows which got copied dynamically.

Thanks
Kunal Chaniyal


This Topic is created by Amjad_Sahi using Email to Topic tool.

@kchaniyal,

There are a few ways to accomplish your task. One way can be via InsertRows method with InsertOptions parameter(s) regarding copy. So, you may insert your desired number of rows while copying the formatting (only) of the first row, then you may import data into those rows accordingly. See the sample code for your reference:
e.g.
Sample code:

Workbook workbook = new Workbook();
            var style = workbook.CreateStyle();
            var flag = new StyleFlag();
            style.Font.IsBold = true;
            flag.FontBold = true;
            workbook.Worksheets[0].Cells.Rows[0].ApplyStyle(style, flag);
            workbook.Worksheets[0].Cells[0, 0].PutValue("First Row we Created");//row, col
            
            workbook.Worksheets[0].Cells.InsertRows(1,100,new InsertOptions() { CopyFormatType = CopyFormatType.SameAsAbove});//you may replace "100" with your desired number of rows.
            workbook.Worksheets[0].Cells[1, 0].PutValue("Second Row we Created");// THIS TEXT will BE BOLD too.
            workbook.Save("e:\\test2\\out1.xlsx");

Hope, this helps a bit.