You must Sign In to post a response.
  • Category: .NET

    Need to generate excel sheet with proper data

    Hi ,

    I am able to generate excel sheet in C#.net.second time am writing data in new row and new column in same excel sheet. like below

    Name Surname A B C A B C D A B C D E A B C F
    Roger R x x x
    Nilesh N x x x x
    Tom C x x x x x
    John F x x x x

    But i need data in follwing format.
    Name Surname A B C D E F
    Roger R x x x
    Nilesh N x x x x
    Tom C x x x x x
    John F x x x x

    above data explain that name and surname present then make it as x otherviz blank the cell.

    Please find the attached excel sheet.

    Please help me out on above issue.

    Thanks in advance.
  • #767821

    Data.xlsx

    Delete Attachment

  • #767823
    Hi,
    You could try the following free .NET Excel API to generate excel file and manipulate data in it: https://visualstudiogallery.msdn.microsoft.com/81c33294-eee9-4683-9cee-a5714cfebf34

  • #767826
    You need to play some sought logic here, I think do not write 'Name Surname' line in excel sheet just append it in a string variable and after you have wrote all data, then just insert that line to first position, just use 'Range' class from EXCEL namespace and insert line at position number 1
    see below snippet

    //Suppose you want to add in the third line
    Range Line = (Range)worksheet.Rows[3];
    Line.Insert();

    hope it helps

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #767827
    Hi,
    Visit here.
    http://www.c-sharpcorner.com/uploadfile/bd6c67/how-to-create-excel-file-using-c-sharp/

  • #767836
    Thnaks for your reply.

    oWB = oXL.Workbooks.Open("d:\\Data.xls", 0, false, 5, "", "", false, XlPlatform.xlWindows, "", true, false, 0, true, false, false);
    Worksheet mySheet = oWB.Sheets[1];
    oRng = oWB.Sheets[1].UsedRange;
    int rr = oRng.Rows.Count;
    int cc = oRng.Columns.Count;

    From above i can find count of columns and rows.But i need to find out the column index by supplying column name .below example
    Name Surname A B C
    tom fale x x x

    by supplying column name A ,i should get column index i.e 3
    by supplying column name B ,i should get column index i.e 4
    by supplying column name C ,i should get column index i.e 5

    How to get column index by column name and check whether column name A,B,C exist in excel sheet?

    i dont want to use dataset or datarow to find.

    Thanks in advance.


Sign In to post your comments