Click here to Skip to main content
15,881,715 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to Export Data from an DataTable to an Excel sheet. I use this to enable the Hyperlinks:

C#
oWB.SaveAs(path + "newsletter.xls", Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookNormal, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value);


the xlWorkbookNormal is the only way to enable the Hyperlink, with all other the Hyperlink will not be displayed. But the Problem with that is that because of that my Formatting stuff dosent work, It only work with xlWorkbookDefault.

How can I display this Formatting style on the normal xlWorkbookNormal:

oXL.DisplayAlerts = false;

                 oWS.Name = "GEKKO Computer GmbH";
                 oWS.Cells.Borders.LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlLineStyleNone;

                 exrngKopf.EntireRow.Font.Bold = true;


What I have tried:

I tried something like that:
C#
int i = 0;
foreach (Microsoft.Office.Interop.Excel.Range c in range.Cells)
{
    string tmp = (c.Value as string);//.TrimStart('=');
    c.Value = string.Empty;
    c.Value2 = string.Empty;
    c.FormulaLocal = tmp;
    i++;
    if (i == 10 || i == 100 || i == 1000 || i == 10000)
    {
        string muell = string.Empty + tmp;
    }


}
Posted
Updated 6-Jul-22 12:34pm
v2
Comments
EstKells 6-Jul-22 11:27am    
I dont Use that I use an FileStream to load the data in the Excel sheet after that I open It with interop formatting it and then save as an real xls file. So I dont need that add methode. I've tried it before without file stream and add data through a loop but in my DataTable there are over 10.000 datas, it took 30 minutes for loading the data
Richard MacCutchan 6-Jul-22 11:40am    
Sorry, but that is the only way I know how to do it.
EstKells 6-Jul-22 11:41am    
no problem, but thank you for your time
matblue25 6-Jul-22 21:17pm    
I don’t know if this will help or not but the “.xls” extension corresponds to the xlWorkbookNormal format. xlWorkbookDefault is the “.xlsx” file format.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900