• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2243
  • Last Modified:

I get error message : Exception from HRESULT: 0x800A03EC when i try to execute som data rows selected from a DataGridView....

Hi

I have a DatagridView where i have a selction box to select transactions listen in the gridview. i can select rows i want to copy over to Excel sheet....!  It works fine when i have norwegan as selected language on my application, but when i select other language as english og swedish i get error message Exception from HRESULT: 0x800A03EC, it happens in code where it first try to draw header text of excel.....it worked before but now it gives a exception message.



The GetValue() , do get string text in different languages.....and it works fine in norwegan, i get expetion only if i change language to swedish or english f.eks...   ????!!!'
 
the code below draws the header of excel sheet.....
 
 try
                {
                    worksheet.Cells[1, 1] = GetValue("vdate");
                    worksheet.Cells[1, 2] = GetValue("bdate");
                    worksheet.Cells[1, 3] = GetValue("reference");
                    worksheet.Cells[1, 4] = GetValue("amount");
                    worksheet.Cells[1, 5] = GetValue("text");
                    worksheet.Cells[1, 6] = GetValue("comment");
                    worksheet.Cells[1, 7] = GetValue("accountno");
                }
                catch (System.Exception e )
                {
                }

Open in new window

0
Adnan
Asked:
Adnan
  • 9
  • 6
  • 2
1 Solution
 
AdnanAuthor Commented:
i have pastet my full function wich execute the excel with selected rows from datagridview.....
       private void ExcelTransactions()
        {
            //System.Globalization.CultureInfo = System.Threading.Thread.CurrentThread.CurrentCulture();
            System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
            List<int> execlProcessIds = new List<int>();
            foreach (Process process in Process.GetProcessesByName("Excel"))
            {
                execlProcessIds.Add(process.Id);
            }
 
           
            try
            {
                Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application();
                excel.Application.Workbooks.Add(true);
                string versjon = excel.Version;
                DsReconItems.MatchItemDataTable table = dsReconItems1.MatchItem;// Tables[0];
 
                Microsoft.Office.Interop.Excel.Worksheet worksheet = (Microsoft.Office.Interop.Excel.Worksheet)excel.ActiveSheet;
                Microsoft.Office.Interop.Excel.Sheets sheets = excel.Worksheets;
                sheets.Add(Missing.Value, Missing.Value, Missing.Value, Missing.Value);
 
                Microsoft.Office.Interop.Excel.Range rg = worksheet.get_Range("A1", "G1");
                Microsoft.Office.Interop.Excel.Range rg2 = worksheet.get_Range("E1", "E1");
 
                int strTemp = (int)ReconManuallyGridView.Rows[i].Cells["Type"].Value;
                //DataGridViewColumnCollection columns = ReconManuallyGridView.Columns;
                int ColumnIndex = 7;
 
                //worksheet.Cells[1, 1] = "vdat";
                //worksheet.Cells[1, 2] = "bdat";
                //worksheet.Cells[1, 3] = "ref";
                //worksheet.Cells[1, 4] = "amt";
                //worksheet.Cells[1, 5] = "txt";
                //worksheet.Cells[1, 6] = "commnt";
                //worksheet.Cells[1, 7] = "acctno";
 
                try
                {
                    worksheet.Cells[1, 1] = GetValue("vdate");
                    worksheet.Cells[1, 2] = GetValue("bdate");
                    worksheet.Cells[1, 3] = GetValue("reference");
                    worksheet.Cells[1, 4] = GetValue("amount");
                    worksheet.Cells[1, 5] = GetValue("text");
                    worksheet.Cells[1, 6] = GetValue("comment");
                    worksheet.Cells[1, 7] = GetValue("accountno");
                }
                catch (System.Exception e )
                {
                }
 
                DsReconItems.ExtraColumnNameDataTable ecTable = AmEngine.Instance.GetExtraFields(myOper);
                Dictionary<String, int> columnPosition = new Dictionary<string, int>();
                foreach (DsReconItems.ExtraColumnNameRow nameRow in ecTable.Rows)
                {
                    if (nameRow.Name == "Comment")
                    {
                        columnPosition.Add(nameRow.Name, 6);
                    }
                    else
                    {
                        ColumnIndex++;
                        worksheet.Cells[1, ColumnIndex] = nameRow.Name;
                        columnPosition.Add(nameRow.Name, ColumnIndex);
                        ((Microsoft.Office.Interop.Excel.Range)worksheet.Cells[1, ColumnIndex]).Interior.ColorIndex = 15;
                        ((Microsoft.Office.Interop.Excel.Range)worksheet.Cells[1, ColumnIndex]).Font.Bold = true;
                        ((Microsoft.Office.Interop.Excel.Range)worksheet.Cells[1, ColumnIndex]).HorizontalAlignment = Microsoft.Office.Interop.Excel.Constants.xlCenter;
                    }
 
                }
 
                Microsoft.Office.Interop.Excel.Range myCell1 = (Microsoft.Office.Interop.Excel.Range)worksheet.get_Range("A1", "G1");
                //rg.Select();
                //bold
                rg.Font.Bold = true;
                // font face
                rg.Font.Name = "Arial";
                //font size
                rg.Font.Size = 10;
 
                rg.HorizontalAlignment = Microsoft.Office.Interop.Excel.Constants.xlCenter;
                // color index
                rg.Interior.ColorIndex = 15;
                // font weight
                // rg.Borders.Weight = 4;
 
                // Border Line style
                //rg.Borders.LineStyle = Microsoft.Office.Interop.Excel.Constants.
                rg.Borders.LineStyle = false;
                // column height
 
                myCell1.Font.Bold = true;
 
                int rowIndex = 0;
                int transactionLimit = 501;
                DsReconItems.MatchItemRow[] miRows = (DsReconItems.MatchItemRow[])dsReconItems1.MatchItem.Select(" recon = true ");
                int countTransactionsChecked = miRows.Length;
                if (countTransactionsChecked >= transactionLimit)
                {
                    DialogResult cannotsend = MessageBox.Show(GetValue("cannotcopytransactions"), GetValue("info"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                    switch (cannotsend)
                    {
                        case DialogResult.OK:
                            {
                                return;
                            }
                    }
 
                }
 
                
                foreach (DsReconItems.MatchItemRow miRow in miRows)
                {
 
                    Guid matchItem_ID = miRow.MatchItem_ID;
                    DsReconItems.MatchItemRow currentAddMIRow = dsReconItems1.MatchItem.FindByMatchItem_ID(matchItem_ID);
                    if (currentAddMIRow != null)
                    {
                        if (currentAddMIRow.Type >= 128)
                        {
                            rowIndex++;
                            ColumnIndex = 0;
                            decimal amnt = (decimal)currentAddMIRow.Amount;
                            //((Microsoft.Office.Interop.Excel.Range)worksheet.Cells[rowIndex + 1, ColumnIndex = 5]).EntireColumn.WrapText = false;
 
                            ((Microsoft.Office.Interop.Excel.Range)worksheet.Cells[rowIndex + 1, ColumnIndex = 1]).Interior.Color = System.Drawing.ColorTranslator.ToWin32(colorRight);
                            ((Microsoft.Office.Interop.Excel.Range)worksheet.Cells[rowIndex + 1, ColumnIndex = 2]).Interior.Color = System.Drawing.ColorTranslator.ToWin32(colorRight);
                            ((Microsoft.Office.Interop.Excel.Range)worksheet.Cells[rowIndex + 1, ColumnIndex = 3]).Interior.Color = System.Drawing.ColorTranslator.ToWin32(colorRight);
                            ((Microsoft.Office.Interop.Excel.Range)worksheet.Cells[rowIndex + 1, ColumnIndex = 4]).Interior.Color = System.Drawing.ColorTranslator.ToWin32(colorRight);
 
 
 
                            worksheet.Cells[rowIndex + 1, ColumnIndex = 1] = currentAddMIRow.VDate.ToShortDateString().Trim();
                            if (currentAddMIRow["Bdate"] != DBNull.Value)
                            {
                                worksheet.Cells[rowIndex + 1, ColumnIndex = 2] = currentAddMIRow.Bdate.ToShortDateString().Trim();
                            }
                            else
                            {
                                worksheet.Cells[rowIndex + 1, ColumnIndex = 2] = "";
                            }
                            worksheet.Cells[rowIndex + 1, ColumnIndex = 3] = currentAddMIRow.Ref.ToString().Trim();
                            ((Microsoft.Office.Interop.Excel.Range)worksheet.Cells[rowIndex + 1, ColumnIndex = 3]).EntireColumn.NumberFormat = "00000";
                            ((Microsoft.Office.Interop.Excel.Range)worksheet.Cells[rowIndex + 1, ColumnIndex = 3]).HorizontalAlignment = Left;
 
 
                            //worksheet.Cells[rowIndex + 1, ColumnIndex = 4] = currentAddMIRow.Amount;
                            if (amnt < 0)
                            {
                                worksheet.Cells[rowIndex + 1, ColumnIndex = 4] = currentAddMIRow.Amount;
                                ((Microsoft.Office.Interop.Excel.Range)worksheet.Cells[rowIndex + 1, ColumnIndex = 4]).Font.Color = System.Drawing.ColorTranslator.ToWin32(colorAmountCredit);
                            }
                            else
                            {
                                worksheet.Cells[rowIndex + 1, ColumnIndex = 4] = currentAddMIRow.Amount;
                                ((Microsoft.Office.Interop.Excel.Range)worksheet.Cells[rowIndex + 1, ColumnIndex = 4]).Font.Color = System.Drawing.ColorTranslator.ToWin32(colorAmountDebit);
                            }
 
                            //Text felt
 
                            DsReconItems.TextRow[] textRows = (DsReconItems.TextRow[])currentAddMIRow.GetTextRows();
                            StringBuilder sb = new StringBuilder();
                            // string tRows = textRows.Replace(" ", "\n");
 
                            if (textRows.Length == 0)
                            {
                                ((Microsoft.Office.Interop.Excel.Range)worksheet.Cells[rowIndex + 1, ColumnIndex = 5]).Interior.Color = System.Drawing.ColorTranslator.ToWin32(colorRight);
                            }
                            else
                            {
                                foreach (DsReconItems.TextRow tRow in textRows)
                                {
                                    // sb.ToString().Substring().Trim()
                                    sb.AppendLine(tRow.Content);
                                    worksheet.Cells[rowIndex + 1, ColumnIndex = 5] = sb.ToString().Trim();
                                    ((Microsoft.Office.Interop.Excel.Range)worksheet.Cells[rowIndex + 1, ColumnIndex = 5]).Interior.Color = System.Drawing.ColorTranslator.ToWin32(colorRight);
                                    ((Microsoft.Office.Interop.Excel.Range)worksheet.Cells[rowIndex + 1, ColumnIndex = 5]).EntireColumn.WrapText = false;
                                }
                            }
 
                            //Comment og extra felt
                            DsReconItems.ExtraRow[] extraRows = (DsReconItems.ExtraRow[])currentAddMIRow.GetExtraRows();
 
                            //if (extraRows.Length == 0)
                            //{
                            //    ((Microsoft.Office.Interop.Excel.Range)worksheet.Cells[rowIndex + 1, columnPosition[((DsReconItems.ExtraColumnNameRow)dr[0]).Name]]).Interior.Color = System.Drawing.ColorTranslator.ToWin32(colorRight);
 
                            //}
                            //else
                            //{
 
                            foreach (DsReconItems.ExtraRow eRow in extraRows)
                            {
                                DsReconItems.ExtraColumnNameRow[] dr = (DsReconItems.ExtraColumnNameRow[])ecTable.Select("Type_ID = " + eRow.Type_ID);
                                worksheet.Cells[rowIndex + 1, columnPosition[((DsReconItems.ExtraColumnNameRow)dr[0]).Name]] = eRow.Content.Trim();
                            }
                            foreach (DsReconItems.ExtraColumnNameRow enRow in ecTable.Rows)
                            {
                                ((Microsoft.Office.Interop.Excel.Range)worksheet.Cells[rowIndex + 1, columnPosition[enRow.Name]]).Interior.Color = System.Drawing.ColorTranslator.ToWin32(colorRight);
                            }
                            //}
                            worksheet.Cells[rowIndex + 1, 7] = currentAddMIRow.AccountNo.Trim();
                            ((Microsoft.Office.Interop.Excel.Range)worksheet.Cells[rowIndex + 1, ColumnIndex = 7]).Interior.Color = System.Drawing.ColorTranslator.ToWin32(colorRight);
 
                        }
                        else
                        {
                            rowIndex++;
                            ColumnIndex = 0;
                            decimal amnt = (decimal)currentAddMIRow.Amount;
                            //((Microsoft.Office.Interop.Excel.Range)worksheet.Cells[rowIndex + 1, ColumnIndex = 5]).EntireColumn.WrapText = false;
 
                            ((Microsoft.Office.Interop.Excel.Range)worksheet.Cells[rowIndex + 1, ColumnIndex = 1]).Interior.Color = System.Drawing.ColorTranslator.ToWin32(colorLeft);
                            ((Microsoft.Office.Interop.Excel.Range)worksheet.Cells[rowIndex + 1, ColumnIndex = 2]).Interior.Color = System.Drawing.ColorTranslator.ToWin32(colorLeft);
                            ((Microsoft.Office.Interop.Excel.Range)worksheet.Cells[rowIndex + 1, ColumnIndex = 3]).Interior.Color = System.Drawing.ColorTranslator.ToWin32(colorLeft);
                            ((Microsoft.Office.Interop.Excel.Range)worksheet.Cells[rowIndex + 1, ColumnIndex = 4]).Interior.Color = System.Drawing.ColorTranslator.ToWin32(colorLeft);
 
 
                            worksheet.Cells[rowIndex + 1, ColumnIndex = 1] = currentAddMIRow.VDate.ToShortDateString().Trim();
 
                            if (currentAddMIRow["Bdate"] != DBNull.Value)
                            {
                                worksheet.Cells[rowIndex + 1, ColumnIndex = 2] = currentAddMIRow.Bdate.ToShortDateString().Trim();
                            }
                            else
                            {
                                worksheet.Cells[rowIndex + 1, ColumnIndex = 2] = "";
                            }
                            worksheet.Cells[rowIndex + 1, ColumnIndex = 3] = currentAddMIRow.Ref.ToString().Trim();
                            ((Microsoft.Office.Interop.Excel.Range)worksheet.Cells[rowIndex + 1, ColumnIndex = 3]).EntireColumn.NumberFormat = "00000";
                            ((Microsoft.Office.Interop.Excel.Range)worksheet.Cells[rowIndex + 1, ColumnIndex = 3]).HorizontalAlignment = Left;
                            //worksheet.Cells[rowIndex + 1, ColumnIndex = 4] = currentAddMIRow.Amount;
                            if (amnt < 0)
                            {
                                worksheet.Cells[rowIndex + 1, ColumnIndex = 4] = currentAddMIRow.Amount;
                                ((Microsoft.Office.Interop.Excel.Range)worksheet.Cells[rowIndex + 1, ColumnIndex = 4]).Font.Color = System.Drawing.ColorTranslator.ToWin32(colorAmountCredit);
                            }
                            else
                            {
                                worksheet.Cells[rowIndex + 1, ColumnIndex = 4] = currentAddMIRow.Amount;
                                ((Microsoft.Office.Interop.Excel.Range)worksheet.Cells[rowIndex + 1, ColumnIndex = 4]).Font.Color = System.Drawing.ColorTranslator.ToWin32(colorAmountDebit);
                            }
                            //Text felt
                            DsReconItems.TextRow[] textRows = (DsReconItems.TextRow[])currentAddMIRow.GetTextRows();
                            StringBuilder sb = new StringBuilder();
 
                            if (textRows.Length == 0)
                            {
                                ((Microsoft.Office.Interop.Excel.Range)worksheet.Cells[rowIndex + 1, ColumnIndex = 5]).Interior.Color = System.Drawing.ColorTranslator.ToWin32(colorLeft);
                            }
                            else
                            {
                                foreach (DsReconItems.TextRow tRow in textRows)
                                {
                                    //sb.AppendLine(tRow.Content.Trim());
                                    sb.AppendLine(tRow.Content);
                                    worksheet.Cells[rowIndex + 1, ColumnIndex = 5] = sb.ToString().Trim();
                                    ((Microsoft.Office.Interop.Excel.Range)worksheet.Cells[rowIndex + 1, ColumnIndex = 5]).Interior.Color = System.Drawing.ColorTranslator.ToWin32(colorLeft);
                                    ((Microsoft.Office.Interop.Excel.Range)worksheet.Cells[rowIndex + 1, ColumnIndex = 5]).EntireColumn.WrapText = false;
 
                                }
                            }
 
                            //Comment felt
                            DsReconItems.ExtraRow[] extraRows = (DsReconItems.ExtraRow[])currentAddMIRow.GetExtraRows();
                            //if (extraRows.Length == 0)
                            //{
                            //    ((Microsoft.Office.Interop.Excel.Range)worksheet.Cells[rowIndex + 1, ColumnIndex = 6]).Interior.Color = System.Drawing.ColorTranslator.ToWin32(colorLeft);
                            //}
                            //else
                            //{
                            foreach (DsReconItems.ExtraRow eRow in extraRows)
                            {
                                DsReconItems.ExtraColumnNameRow[] dr = (DsReconItems.ExtraColumnNameRow[])ecTable.Select("Type_ID = " + eRow.Type_ID);
                                worksheet.Cells[rowIndex + 1, columnPosition[((DsReconItems.ExtraColumnNameRow)dr[0]).Name]] = eRow.Content.Trim();
                            }
                            foreach (DsReconItems.ExtraColumnNameRow enRow in ecTable.Rows)
                            {
                                ((Microsoft.Office.Interop.Excel.Range)worksheet.Cells[rowIndex + 1, columnPosition[enRow.Name]]).Interior.Color = System.Drawing.ColorTranslator.ToWin32(colorLeft);
                            }
                            //}
 
                            worksheet.Cells[rowIndex + 1, ColumnIndex = 7] = currentAddMIRow.AccountNo.Trim();
                            ((Microsoft.Office.Interop.Excel.Range)worksheet.Cells[rowIndex + 1, ColumnIndex = 7]).Interior.Color = System.Drawing.ColorTranslator.ToWin32(colorLeft);
                        }
 
                    }
 
                    excel.Visible = true;
                    worksheet.Columns.AutoFit();
                    worksheet.Rows.AutoFit();
                    //worksheet.Cells.AutoFit();
                    //worksheet.Rows.WrapText = true;
                    worksheet.Activate();
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(GetValue("cannotopenexcel") + "\n" + ex.Message, GetValue("error"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                Process[] processes = Process.GetProcessesByName("Excel");
 
                foreach (Process process in processes)
                {
                    if (!execlProcessIds.Contains(process.Id))
                    {
                        process.Kill();
                    }                        
                }          
                return;
            }
        }

Open in new window

0
 
DabasCommented:
Which line causes the error?
0
 
Bob LearnedCommented:
You might be able to go in a different direction, and use OLE DB to open an Excel worksheet as a DataTable, and get the data, or bind the DataGridView directly to the DataTable.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
AdnanAuthor Commented:
line 40 causes the error
0
 
DabasCommented:
It looks like you have a function named GetValue, which causes the exception. Have you given us the code for it?
I also suggest that at line 49, you gather more information about your exception and post its StackTrace in a code snippet

Dabas
0
 
AdnanAuthor Commented:
yes it is because of GetValue() function to get the correct language string, and it works fine when i have norwegan as language, but when i change the language to swedish then i get the exception. i have pastet the ALL code wich execute the excel sheet...look at the comment 02.13.2009 at 09:52AM GMT, ID: 23631183


here is the stacktrace from exception i get:

at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
   at Microsoft.Office.Interop.Excel.Range.set__Default(Object RowIndex, Object ColumnIndex, Object )
   at Adra.AMDesk.ReconManually.ExcelTransactions() in C:\FoU\AccountMatch.Net2005\AMDesk\ReconManually.cs:line 2458
0
 
DabasCommented:
And what does line 2458 of ReconManually.cs show?

And no, I do not see the GetValue function in your comment. Maybe you can point to the line where that function is declared?

Dabas


0
 
AdnanAuthor Commented:
line 2458 is :   worksheet.Cells[1, 1] = GetValue("vdate");

the first line to set the columns, i get exception on this line...

here is the code declared for the getvalue function....i hope it helps ;)
  public string GetValue(string id)
        {
            return LanguageResource.GetText(id, myLanguageName, "Adra.AMDesk.Strings", assembly);
        }
0
 
DabasCommented:
And do you have the code for the LanguageResource.GetText function?

I suggest you surround this particular line with a try catch too, I am sure this is what is causing your exception.
Note that the stacktrace is complaining about a call to Excel.Range.set__Default, etc, which is not done from your code.

Also "ForwardCallToInvokeMember" indicates that a call is made to a foreign assembl

Dabas
0
 
AdnanAuthor Commented:
sorry here is the code for lang resource......

so ho can i call to excel.Range.set_default???
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Resources;
using System.Threading;
using System.Globalization;
 
namespace Adra.Language
{
    public class LanguageResource
    {
        private static Hashtable myLanguageHash;
 
        public LanguageResource()
        {
            
        }
 
        public static void Initialize()
        {
            lock (typeof(LanguageResource))
            {
                if (myLanguageHash == null)
                {
                    myLanguageHash = new Hashtable();
                }
            }
        }
 
        public static string GetText(string id, string language, string baseName, System.Reflection.Assembly assembly)
        {
            if (myLanguageHash == null)
            {
                Initialize();
                if (myLanguageHash == null)
                {
                    throw new xCeptionDeadConnection("No object");
                }
            }
 
            ResourceManager resManager;
            if (myLanguageHash.ContainsKey(baseName))
            {
                resManager = (ResourceManager)myLanguageHash[baseName];
            }
            else
            {
                resManager = new ResourceManager(baseName, assembly);
                myLanguageHash.Add(baseName, resManager);
            }
 
            // Language set in AMMain on entry. Not safe to change these properties after app started
            if (language != "") //Don't set culture if language is empty. Default is used.
            {
                try
                {
                    Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture(language);
                    Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(language);
                }
                catch { }
            }
 
            try
            {
                return resManager.GetString(id);
            }
            catch (Exception)
            {
                string defaultReturn = "*Error*";
                return defaultReturn;
            }
 
        }
 
        public static string GetShortLanguageWeb(string[] languages)
        {
            string shortLang;
            if (languages.Length == 0)
			{
                shortLang = "en";
			}
            else if (languages[0].ToUpper().IndexOf("NO") >= 0)
			{
                shortLang = "no";
			}
            else if (languages[0].ToUpper().IndexOf("SV") >= 0)
			{
                shortLang = "sv";
			}
			else
			{
                shortLang = "en";
			}
            return shortLang;
        }
 
        public static string GetShortLanguageDesk(string language)
        {
            string shortLang;
            if (language.ToUpper().IndexOf("NO") >= 0)
            {
                shortLang = "no";
            }
            else if (language.ToUpper().IndexOf("SV") >= 0)
            {
                shortLang = "sv";
            }
            else
            {
                shortLang = "en";
            }
            return shortLang;
        }
 
        public static string GetCultureFromShortLang(string shortLang)
        {
            switch (shortLang)
            {
                case "nb":
                    return "nb-NO";
                case "no":
                    return "nb-NO";
                case "sv":
                    return "sv-SE";
                case "en":
                    return "en-GB";
                default:
                    return "en-GB";
            }
        }
    }
 
}

Open in new window

0
 
DabasCommented:
Hmmm..

NO Excel there, so I assume I may have been wrong

Just to be sure as to the cause of the error, can you change line 2458 to

string a =  GetValue("vdate");
I am interested in knowing what the value is that should be going into Cell[1,1]

Dabas
0
 
AdnanAuthor Commented:
the value of the strin a = is a string   "Date"

i didet like this:  
string a = GetValue("vdate");
                    MessageBox.Show(GetValue("vdate"));

and it works fine in swedish and norwegan....but i dont understand why it wont work when i change the line to   worksheet.Cells[1, 1] = GetValue("vdate");
0
 
AdnanAuthor Commented:
??
0
 
AdnanAuthor Commented:
dOES ANY ONE NOW HOPW TO MAKE A csv FILE TO READ COLUMN HEADERS IN MY CASE?
OR HOW CAN I CREATE A csv FILE...I HAVE NEVER DONE IT BEFORE...?!"
0
 
Bob LearnedCommented:
This is what I use to read a CSV file:


using System;
using System.Data;
using System.Diagnostics;
using System.IO;
 
public class FasterCsvReader
{
 
    public static double ReadIntoTable(string fileName, DataTable table)
    {
        Stopwatch watch = new Stopwatch();
        watch.Start();
 
        using (StreamReader reader = new StreamReader(fileName))
        {
            while (!reader.EndOfStream)
            {
                string input = reader.ReadLine();
                string[] fields = input.Split(',');
                table.Rows.Add(fields);
            }
        }
 
        double totalSeconds = watch.Elapsed.TotalSeconds;
 
        watch.Stop();
 
        return totalSeconds;
    }
 
}

Open in new window

0
 
AdnanAuthor Commented:
But i have a Dataset wich i can get the name of headers i want to dispaly in my excel.....so how can i make datable CSV to export those headers i want from dataset....i have code i am working with...

Can somone please help finsih this prob...


try
            {
                
                
                // Get the datatable to export
                DsReconItems.MatchItemDataTable dt = dsReconItems1.MatchItem;
                //DataTable dtEmployee = dsEmployee.Tables["Employee"].Copy();
 
                // Specify the column list to export
                int[] iColumns = {2,3,10,4,16,14};
 
                // Export the details of specified columns to CSV
                //int iColCount = dt.Columns.Count;
                for (int i = 0; i < iColumns; i++)
                {
                    sw.Write(dt.Columns[i]);
                    if (i < iColumns - 1)
                    {
                        sw.Write(",");
                    }
                }
 
            }
            catch(System.Exception Ex)
            {
               
            }

Open in new window

0
 
DabasCommented:
I fail to see what the CSV headers have to do with the original question
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 9
  • 6
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now