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

    Excel to excel conversion with desired format fields

    hi all;
    i need to create an application in C# that takes multiple excel files with same and fix fields but different contents and convert them into another excel files with predefined fields .
    For e.g:-
    File1 &2 &3 etc with fields
    ROLL
    NAME
    ADDRESS
    CONTACT NO

    converted to

    File 1,2,3 with fields
    RNO
    SNAME
    PERMANENT ADDRESS
    MOBILE
    with same contents.
    I hope i was successful in conveying what i need to to do.
  • #765280
    Hi sidyusuf ,

    that's possible, but while implement the code logic then only we can give some what better solution, I already done the same stuff in my previous project, but i don't have that part of code at present.

    Request you to refer below link this might be helpful to you.
    http://www.dotnetspider.com/resources/45059-Export-Excel-To-SQL-DataBase.aspx

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #765377
    Not sure if I have understood you correctly, do you mean that you want to copy one excel document to another for example, File 1 to another File1, with different headers but same contents? If this is the case, then you can refer to following codes:
    Workbook workbook = new Workbook();
    workbook.LoadFromFile(Path of File 1);
    Worksheet worksheet = workbook.Worksheets[0];

    Workbook workbook2 = new Workbook();
    workbook2.LoadFromFile(Path of another File1);
    Worksheet worksheet2 = workbook2.Worksheets[0];

    int i = 2;
    int colunmCount = worksheet.Columns.Count();
    foreach (CellRange range in worksheet.Columns[0])
    {
    CellRange sourceRange = worksheet.Range[1, 1, range.Row, colunmCount];
    CellRange destRange = worksheet2.Range[i, 1, i, colunmCount];
    worksheet.Copy(sourceRange, destRange, true);
    }
    worksheet2.DeleteRow(2);

    workbook2.SaveToFile("another File1", ExcelVersion.Version2010);
    System.Diagnostics.Process.Start("another File1");
    This solution was based on a free .net excel library(https://freenetexcel.codeplex.com) which I often used to manipulate excel files like create, edit, convert, copy etc. You could give a try.

  • #765381
    So you want to copy data from one excel sheet to another right ?
    You need to use EXCEL automation for it, I have a below snippet to copy data from one excel to another
    see below
    public void CopyRanges()
    {
    // only one instance of excel
    Excel.Application excelApplication = new Excel.Application();

    srcPath="C:\\Documents and Settings\\HARRY\\Desktop\\incident.csv";
    Excel.Workbook srcworkBook = excelApplication.Workbooks.Open(srcPath);
    Excel.Worksheet srcworkSheet = srcworkBook.Worksheets.get_Item(1);

    destPath = "C:\\Documents and Settings\\HARRY\\Desktop\\FIXED Aging incident Report.xls";
    Excel.Workbook destworkBook = excelApplication.Workbooks.Open(destPath,0,false);
    Excel.Worksheet destworkSheet = destworkBook.Worksheets.get_Item(1);

    Excel.Range from = srcworkSheet.Range("C1:C100");
    Excel.Range to = destworkSheet.Range("C1:C100");

    // if you use 2 instances of excel, this will not work
    from.Copy(to);

    destworkBook.SaveAs("C:\\Documents and Settings\\HARRY\\Desktop\\FIXED Aging incident Report " + DateTime.Now.ToString("MM_dd_yyyy") + ".xls");
    srcxlApp.Application.DisplayAlerts = false;
    destxlApp.Application.DisplayAlerts = false;
    destworkBook.Close(true, null, null);
    srcworkBook.Close(false, null, null);
    excelApplication.Quit();
    }

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


Sign In to post your comments