none
Combine XLS file and HTML files into XLSX file RRS feed

  • Question

  • Hi all, this is my first time posting and I am having a problem in researching how to combine XLS and HTML into a XLSX.

    I would like to avoid using Excel directly to create excel file (using OLEDB Automation or Excel Interop objects). Ideally I would like to use any open source class libraries with some documentation and samples.


    Here is the scenario I would like to achieve:

    User has one large XLS file and multiple HTML files with tables (I cannot change this).

    Depending on some user selections I need to generate new XLSX file (I can change this into XLS) from a part of the specific XLS sheet and from an HTML file which has a same name as that sheet.


    Any guidelines would be appreciated, if possible please provide some links or snippet codes for any of required task.

    Thank you in advance.



    • Edited by AClausen Wednesday, July 24, 2013 8:54 AM Removing some strange characters
    Wednesday, July 24, 2013 8:53 AM

Answers

  • Hello,
    Welcome to MSDN Forum !

    According to your description, I know that you encounter some issue about  how to combine XLS and HTML into a XLSX.We suggest you  using OpenXML, but this one is not an  open source lib .If you agree to use OpenXML, then we can move this thread to OfficeDev Forum , then you need to  create a new post there .


    OfficeDev forums:  http://social.msdn.microsoft.com/forums/en-us/homecategory=officedev&filter=alltypes&sort=lastpostdesc

    This moderator and community will be glad to help you .Hope these helps, if you have any problems, please feel free to let me know.

    Best Regards,

    Lilia

    Thursday, July 25, 2013 7:56 AM
    Moderator
  • Hi, you can also try this .NET Excel dll, although it is not an open source I think you will find it very useful.

    It will enable you to convert between XLS, XLSX and HTML files in .NET with ease.

    Here is a sample code for your requirements:

    ExcelFile largeXLS = ExcelFile.Load(desktop + "\\User Excel.xls");
    ExcelFile newXLSX = new ExcelFile();
    
    // Random sheet selection.
    int randomSheet = new Random().Next(largeXLS.Worksheets.Count);
    ExcelWorksheet sheet = largeXLS.Worksheets[randomSheet];
    
    // Combine XLS sheet and HTML file into a XLSX file.
    newXLSX.Worksheets.AddCopy("Sheet from XLS", sheet);
    ExcelFile htmlFile = ExcelFile.Load(desktop + "\\" + sheet.Name + ".html");
    newXLSX.Worksheets.AddCopy("Sheet from HTML", htmlFile.Worksheets.ActiveWorksheet);
    
    // Save newXLSX file.
    newXLSX.Save(desktop + "\\New Excel.xlsx");
    • Proposed as answer by Casere73 Wednesday, July 31, 2013 8:33 AM
    • Marked as answer by AClausen Wednesday, July 31, 2013 8:43 AM
    Wednesday, July 31, 2013 8:30 AM

All replies

  • Hello,
    Welcome to MSDN Forum !

    According to your description, I know that you encounter some issue about  how to combine XLS and HTML into a XLSX.We suggest you  using OpenXML, but this one is not an  open source lib .If you agree to use OpenXML, then we can move this thread to OfficeDev Forum , then you need to  create a new post there .


    OfficeDev forums:  http://social.msdn.microsoft.com/forums/en-us/homecategory=officedev&filter=alltypes&sort=lastpostdesc

    This moderator and community will be glad to help you .Hope these helps, if you have any problems, please feel free to let me know.

    Best Regards,

    Lilia

    Thursday, July 25, 2013 7:56 AM
    Moderator
  • Hi,

    Thank you for the response, I really appreciate it.

    I will first try to accomplish my task alone with OpenXML SDK if I ran into some issues I will post them on OfficeDev forum.

    Thank you again.

    Friday, July 26, 2013 8:12 AM
  • Hi, you can also try this .NET Excel dll, although it is not an open source I think you will find it very useful.

    It will enable you to convert between XLS, XLSX and HTML files in .NET with ease.

    Here is a sample code for your requirements:

    ExcelFile largeXLS = ExcelFile.Load(desktop + "\\User Excel.xls");
    ExcelFile newXLSX = new ExcelFile();
    
    // Random sheet selection.
    int randomSheet = new Random().Next(largeXLS.Worksheets.Count);
    ExcelWorksheet sheet = largeXLS.Worksheets[randomSheet];
    
    // Combine XLS sheet and HTML file into a XLSX file.
    newXLSX.Worksheets.AddCopy("Sheet from XLS", sheet);
    ExcelFile htmlFile = ExcelFile.Load(desktop + "\\" + sheet.Name + ".html");
    newXLSX.Worksheets.AddCopy("Sheet from HTML", htmlFile.Worksheets.ActiveWorksheet);
    
    // Save newXLSX file.
    newXLSX.Save(desktop + "\\New Excel.xlsx");
    • Proposed as answer by Casere73 Wednesday, July 31, 2013 8:33 AM
    • Marked as answer by AClausen Wednesday, July 31, 2013 8:43 AM
    Wednesday, July 31, 2013 8:30 AM
  • Hi,

    This looks great, thank you very much.

    Wednesday, July 31, 2013 8:44 AM