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

    How to set this Function in C#

    Hi

    How to set this Excel Code

    this is my code below . But I need how to set 1.Autofit,2. Borders in all data
    using below code in C# ? any one guide me.

    var workbook = new XLWorkbook();
    var worksheet = workbook.Worksheets.Add()
  • #768681
    Hi,

    We can make both Autofit and Borders easily in the C# code.



    _range = objSheet.get_Range("A4", "A4"); // This is for the range of the worksheet
    borders = _range.Borders;
    borders.LineStyle = Excel.XlLineStyle.xlContinuous; // This will give you thin lines.
    borders.Weight = 2d; // 2d lines
    (or)
    borders.Weight = 3d; //3d lines
    (or)
    borders.Weight = 4d; //4d lines



    For Autofit, We can easily create code in one line code.


    Worksheet sheet = workbook.Worksheets[0];
    sheet.AutoFitColumn(1); //This will autofit the column

    Thanks,
    Mani

  • #768711
    If you are inserted to add new worksheet to the excel file. This code snippet will help you to open an existing Excel file and add a new worksheet
     
    var xlNewSheet = (Excel.Worksheet)worksheets.Add(worksheets[1], Type.Missing,
    Type.Missing, Type.Missing); xlNewSheet.Name = "YourNewsheet";
    xlNewSheet.Cells[1, 1] = "New sheet content";
    To add worksheet in selected excel document
    xlNewSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(2);
    xlNewSheet.Select();


  • Sign In to post your comments