Click here to Skip to main content
15,921,174 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a problem with saving a list of name and surnme in excel from c# (window form)
there are problem with some character like 'ë', I dont have that problem i Word just in excel.

ex I am using that code:
string Text= File.ReadAllText(textbox.Text, System.Text.Encoding.Default);


the message in Excel is this: the file you trying to open ".xls" is in different format than specified by extension..


what should I do....


that's not homework, understand me please...!

God bless you
Posted
Updated 3-May-12 1:26am
v2

Try using this

C#
string Text= File.ReadAllText(textbox.Text, System.Text.Encoding.Unicode);
 
Share this answer
 
C#
//fxn that exports content of a datagridview object to an excel file

//note: excel_file represents the complete physical address of excel file eg C:/myexcel.xls


        public  void export_datagridview_to_excel(DataGridView dgv, string excel_file)
        {
            int cols;
            //open file
            StreamWriter wr = new StreamWriter(excel_file);

            //determine the number of columns and write columns to file
            cols = dgv.Columns.Count;
            for (int i = 0; i < cols; i++)
            {
                wr.Write(dgv.ColumnsIdea.Name.ToString().ToUpper() + "\t");
            }

            wr.WriteLine();

            //write rows to excel file
            for (int i = 0; i < (dgv.Rows.Count - 1); i++)
            {
                for (int j = 0; j < cols; j++)
                {
                    if (dgv.RowsIdea.Cells[j].Value != null)
                        wr.Write(dgv.RowsIdea.Cells[j].Value + "\t");
                    else
                    {
                        wr.Write("\t");
                    }
                }

                wr.WriteLine();
            }

            //close file
            wr.Close();

}
 
Share this answer
 

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