Question

What is the default encoding off Microsoft Excel 2007?

Asked by: toshi_

I tried a list of encoding my CSV files to export, but Microsoft Excel 2007 didn't want to recognise it. Her is the list:
- Response.ContentEncoding = System.Text.Encoding.GetEncoding("iso-8859-2");
- Response.ContentEncoding = System.Text.Encoding.GetEncoding("windows-1256");
- Response.ContentEncoding = System.Text.Encoding.GetEncoding("iso-8859-1");
- Response.ContentEncoding = System.Text.Encoding.Default;
- Response.ContentEncoding = System.Text.Encoding.UTF8;
- Response.ContentEncoding = System.Text.Encoding.UTF7;
- Response.ContentEncoding = System.Text.Encoding.Default;
- Response.ContentEncoding = System.Text.Encoding.BigEndianUnicode
- Response.ContentEncoding = System.Text.Encoding.ASCII
- Response.ContentEncoding = System.Text.Encoding.UTF32

using System;
using System.Text;
using System.Data;
using System.Globalization;
using System.Threading;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Ecowaste.E_plan.DomainLayer;
 
namespace Ecowaste.E_plan.WebSite
{
    public partial class generatingAllLevels : System.Web.UI.Page
    {
 
        private DataTable allLevelsAndForecast_;
        private string communityNameClean_;
 
        private Community theCommunity_;
        private Account Account_;
 
        private LanguageParser Parser_;
 
 
        protected override void OnInit(EventArgs e)
        {
            Account_ =  VarSession.Account;
            Parser_ = new LanguageParser();
            base.OnInit(e);
        }
 
 
        protected void Page_Load(object sender, EventArgs e)
        {
            theCommunity_              = VarSession.Community;
 
            CultureInfo cultureInfo     = Thread.CurrentThread.CurrentCulture;
            TextInfo textInfo           = cultureInfo.TextInfo;
            communityNameClean_         = textInfo.ToTitleCase(theCommunity_.Db_name.Replace("_", " "));
            allLevelsAndForecast_       = RecoverValuesFromCache();
 
            if (bool.Parse(Request.Params["excel2003"]))
            {
                GiveExcellResponse();
            }
            else
            {
                GiveCSSResponse();
            }
        }
 
 
 
        private DataTable RecoverValuesFromCache()
        {
            string _wt;
            try
            {
                _wt = HttpContext.Current.Cache["Export_WT_" + theCommunity_.Db_name].ToString();
            } catch (NullReferenceException ex)
            {
                Console.Write("generatingAllLevels->RecoverValuesFromCache; ex:" + ex.Message);
                _wt = "";
            }
 
            // -- si c'est l'admin qui exporte, pas de type de deches, ils sont tous exportés.
            if(Account_.AccountType == DomainLayer.AccountType.AdminAccount || Account_.Id == 1000000)
            {
                _wt = "";
            }
 
            // -- RECOVER FROM CACHE -----------------------
            try
            {
 
                if (System.Web.HttpContext.Current.Cache["levelPrevision_" + _wt + "_"+theCommunity_.Db_name] != null)
                {
                    if(((DataTable)System.Web.HttpContext.Current.Cache["levelPrevision_"  +_wt+ "_" +theCommunity_.Db_name]).Rows.Count > 0)
                        return (DataTable) System.Web.HttpContext.Current.Cache["levelPrevision_" +_wt+ "_" + theCommunity_.Db_name];
                }
            } catch (System.NullReferenceException ex)
            {
                Console.Write("generatingAllLevels.aspx.cs->RecoverValuesFromCache; ex:" + ex.Message);
            }
            return (DataTable) System.Web.HttpContext.Current.Cache["levelPrevision_"+ _wt + "_" + theCommunity_.Db_name];
            // -- ------------------ -----------------------
        }
 
        private void GiveCSSResponse()
        {
            Response.Clear();
            Response.Buffer = true;
            Response.ContentType = "text/csv";
            //Response.ContentEncoding = System.Text.Encoding.GetEncoding("iso-8859-2");
            //Response.ContentEncoding = System.Text.Encoding.GetEncoding("windows-1256");
            //Response.ContentEncoding = System.Text.Encoding.GetEncoding("iso-8859-1");
            Response.ContentEncoding = System.Text.Encoding.UTF8;
            Response.Charset = "";
            this.EnableViewState = false;
            Response.AddHeader("Content-Disposition", "filename=" + theCommunity_.Db_name + "_ExportCSVContainersStatusLevels.csv");
 
            Response.Write(GenerateCSVWithAllContainersLevels().ToString());
 
            Response.End();
        }
 
 
        private void GiveExcellResponse()
        {
            Response.Clear();
            Response.Buffer = true;
            Response.ContentType = "application/vnd.ms-excel";
            //Response.ContentEncoding = System.Text.Encoding.GetEncoding("iso-8859-15");
            //Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");
            //Response.ContentEncoding = System.Text.Encoding.GetEncoding("iso-8859-1");
 
            //Response.ContentEncoding = System.Text.Encoding.UTF7;    // ---> ok pour les char spéciaux, dictionnary KO.
            //Response.ContentEncoding = System.Text.Encoding.UTF8;    // ---> ok pour dictionnary, char spéciaux KO.
            //Response.ContentEncoding = System.Text.Encoding.ASCII;   // ---> ok pour dictionnary, char spéciaux en "?" 
            //Response.ContentEncoding = System.Text.Encoding.Unicode; // ---> ko, affiche en html. 
            //Response.ContentEncoding = System.Text.Encoding.Default; // --->  ko, comme utf8
            Response.ContentEncoding = System.Text.Encoding.UTF7; // --->  ko, comme utf8
 
            Response.Charset = "";
            this.EnableViewState = false;
            Response.AddHeader("Content-Disposition", "filename=" +theCommunity_.Db_name+ "_ExportContainersStatusLevels.xls");
 
            Response.Write(GenerateHeaderInfoForLevels().ToString());
            Response.Write("<table border=1>");
            Response.Write(GenerateExcelHeader().ToString());
            Response.Write(GenerateExcelWithAllContainersLevels().ToString());
            Response.Write("</table>");
 
            Response.End();
        }
 
 
#region page construction
        private StringBuilder GenerateHeaderInfoForLevels()
        {
 
            StringBuilder _htmlHeaderInfo = new StringBuilder();
            _htmlHeaderInfo.Append("<table border=0 style='font-size:14px; font-weight:bold;'>");
                _htmlHeaderInfo.Append("<tr>");
                    _htmlHeaderInfo.Append("<td class='header_lab'><lng id=date/></td>    <td class='header_val' align='left'>" +DateTime.Now.ToShortDateString()+ " " +DateTime.Now.ToShortTimeString()+ "</td>");
                _htmlHeaderInfo.Append("</tr>");
                _htmlHeaderInfo.Append("<tr>");
                    _htmlHeaderInfo.Append("<td class='header_lab'><lng id=Community/></td>   <td class='header_val' align='left'> "+communityNameClean_+"</td>");
                _htmlHeaderInfo.Append("</tr>");
                _htmlHeaderInfo.Append("<tr>");
                    _htmlHeaderInfo.Append("<td class='header_lab' style='background-color:#ff66aa;'><lng id=ColoredBackground/></td>    <td class='header_val' align='left'><lng id=InfoOlderThan30H/></td>");
                _htmlHeaderInfo.Append("</tr>");
                _htmlHeaderInfo.Append("<tr>");
                    _htmlHeaderInfo.Append("<td>&nbsp;</td>");
                _htmlHeaderInfo.Append("</tr>");
                _htmlHeaderInfo.Append("<tr>");
                    _htmlHeaderInfo.Append("<td>&nbsp;</td>");
                _htmlHeaderInfo.Append("</tr>");
            _htmlHeaderInfo.Append("</table>");
 
            StringBuilder _Translated = Parser_.Translate(_htmlHeaderInfo);
 
            return _Translated;
        }
 
 
 
        private StringBuilder GenerateExcelHeader()
        {
            StringBuilder _htmlHeader = new StringBuilder();
 
                _htmlHeader .Append("<tr style='font-weight:bold; background-color:#eeefee; font-size:14px'>");
                    _htmlHeader.Append("<td width=200><lng id=ContainerNo/>        </td>");
                    _htmlHeader.Append("<td width=200><lng id=ContainerId/>        </td>");
                    _htmlHeader.Append("<td><lng id=Address/>                      </td>");
                    _htmlHeader.Append("<td><lng id=City/>                         </td>");
                    _htmlHeader.Append("<td width=200><lng id=ContainerWasteType/> </td>");
                    _htmlHeader.Append("<td><lng id=WasteMass/> [Kg]               </td>");
                    _htmlHeader.Append("<td><lng id=level/>-Min [%]                </td>");
                    _htmlHeader.Append("<td><lng id=level/> [%]                    </td>");
                    _htmlHeader.Append("<td><lng id=level/>-Max [%]                </td>");
                    _htmlHeader.Append("<td><lng id=LastDateLevel/>                </td>");
                    _htmlHeader.Append("<td><lng id=ContainerForecast/>            </td>");
                _htmlHeader .Append("</tr>");
 
            StringBuilder _Translated = Parser_.Translate(_htmlHeader);
 
            return _Translated;
        }
 
 
 
        private StringBuilder GenerateExcelWithAllContainersLevels()
        {
            StringBuilder _htmlPage = new StringBuilder();
 
            //int i = 0; 
            foreach(DataRow row in allLevelsAndForecast_.Rows)
            {
                // TODO : changer la couleur selon la dernière date.
                DateTime last   = (DateTime) row["last_punched_level"];
                DateTime now    = DateTime.Now;
                int      total  = (int)(now - last).TotalHours;
                
                if(total < 30)
                {
                    _htmlPage.Append("<tr>");
                }else
                {
                    _htmlPage.Append("<tr bgcolor='#ff66aa'>");
                }
                    _htmlPage.Append("<td>" + row["container_no"] + "</td>");
                    _htmlPage.Append("<td>" + row["container_id"] + "</td>");
                    _htmlPage.Append("<td>" +row["address"]             + "</td>");
                    _htmlPage.Append("<td>" +row["city"]                + "</td>");
                    _htmlPage.Append("<td>" +row["waste_type"]          + "</td>");
                    _htmlPage.Append("<td>" +row["mass"]                + "</td>");
                    _htmlPage.Append("<td>" +row["level_percent_min"]   + "</td>");
                    _htmlPage.Append("<td>" +row["level_percent"]       + "</td>");
                    _htmlPage.Append("<td>" +row["level_percent_max"]   + "</td>");
                    _htmlPage.Append("<td>" + ((DateTime)row["last_punched_level"]).ToString("ddd, dd-MMM") + 
                                     " " +((DateTime)row["last_punched_level"]).ToShortTimeString()+ 
                        "</td>");
                    _htmlPage.Append("<td>" +row["forecast_days"]   + "</td>");
                _htmlPage.Append("</tr>");
            }
            StringBuilder _Translated = Parser_.Translate(_htmlPage);
 
            return _Translated;
        }
 
        public StringBuilder GenerateCSVWithAllContainersLevels()
        {
            StringBuilder CSVPage_;
            CSVPage_ = new StringBuilder();
 
            CSVPage_.Append(SetExportCSVHeader().ToString());
            CSVPage_.Append(SetContentCSVHeader().ToString());
            CSVPage_.Append(SetAllContainersLevelsCSV().ToString());
 
            return CSVPage_;
        }
 
        private StringBuilder SetExportCSVHeader()
        {
 
            StringBuilder _accuExportHeader = new StringBuilder();
            string separator = ";";
 
            /// -------------- PAGE HEADER -----------------------//
            /// 
             _accuExportHeader.Append("\n"); //nécessaire pour la traduction
 
            _accuExportHeader.Append("<lng id=date/>" + separator + DateTime.Now.ToShortDateString()+ " " +DateTime.Now.ToShortTimeString()+ "\n");
            _accuExportHeader.Append("<lng id=Community/>" + separator + communityNameClean_ + "\n");
            _accuExportHeader.Append("*" + separator + "<lng id=InfoOlderThan30H/>\n");
            _accuExportHeader.Append(" " + separator + "\n");
            _accuExportHeader.Append(" " + separator + "\n");
 
            /// -------------- END PAGE HEADER ----------------------------//
            /// 
            /// 
            /// 
 
            StringBuilder _Translated = Parser_.Translate(_accuExportHeader);
 
            return _Translated;
        }
 
        private StringBuilder SetContentCSVHeader()
        {
 
            StringBuilder _TempHeader = new StringBuilder();
            string separator = ";";
 
            _TempHeader.Append("\n"); //nécessaire pour la traduction
 
            _TempHeader.Append("<lng id=ContainerNo/>" + separator);
            _TempHeader.Append("<lng id=ContainerId/>" + separator);
            _TempHeader.Append("<lng id=Address/>" + separator);
            _TempHeader.Append("<lng id=City/>" + separator);
            _TempHeader.Append("<lng id=ContainerWasteType/>" + separator);
            _TempHeader.Append("<lng id=WasteMass/>" + separator);
            _TempHeader.Append("<lng id=level/>-Min [%]" + separator);
            _TempHeader.Append("<lng id=level/> [%]" + separator);
            _TempHeader.Append("<lng id=level/>-Max [%]" + separator);
            _TempHeader.Append("<lng id=LastDateLevel/>" + separator);
            _TempHeader.Append("<lng id=ContainerForecast/>" + separator +"\n");
 
 
            StringBuilder _Translated = Parser_.Translate(_TempHeader);
 
            return _Translated;
        }
 
        private StringBuilder SetAllContainersLevelsCSV()
        {
            StringBuilder _accuContainers = new StringBuilder();
            string separator = ";";
 
            foreach (DataRow row in allLevelsAndForecast_.Rows)
            {
                // TODO : changer la couleur selon la dernière date.
                DateTime last = (DateTime)row["last_punched_level"];
                DateTime now = DateTime.Now;
                int total = (int)(now - last).TotalHours;
 
                _accuContainers.Append(row["container_no"] + separator);
                _accuContainers.Append(row["container_id"] + separator);
                _accuContainers.Append(row["address"] + separator);
                _accuContainers.Append(row["city"] + separator);
                _accuContainers.Append(row["waste_type"] + separator);
                _accuContainers.Append(row["mass"] + separator);
                _accuContainers.Append(row["level_percent_min"] + separator);
                _accuContainers.Append(row["level_percent"] + separator);
                _accuContainers.Append(row["level_percent_max"] + separator);
                _accuContainers.Append(((DateTime)row["last_punched_level"]).ToString("ddd, dd-MMM") +
                                 " " + ((DateTime)row["last_punched_level"]).ToShortTimeString() + separator);
                _accuContainers.Append(row["forecast_days"] + separator);
                if (total >= 30)
                {
                    _accuContainers.Append("*");
                }
                _accuContainers.Append("\n");
            }
            StringBuilder _Translated = Parser_.Translate(_accuContainers);
 
            return _Translated;
        }
        #endregion
 
    }
}

                                  
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
267:
268:
269:
270:
271:
272:
273:
274:
275:
276:
277:
278:
279:
280:
281:
282:
283:
284:
285:
286:
287:
288:
289:
290:
291:
292:
293:
294:
295:
296:
297:
298:
299:
300:
301:
302:
303:
304:
305:
306:
307:
308:
309:
310:
311:
312:
313:
314:
315:
316:
317:
318:
319:
320:
321:
322:
323:
324:
325:
326:
327:
328:
329:
330:
331:
332:
333:
334:
335:
336:
337:
338:

Select allOpen in new window

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-08-31 at 08:53:50ID24695136
Tags

Microsoft Visual Studio 2005 .NET

,

Microsoft Excel 2007

Topics

.NET Framework 2.x

,

Microsoft Excel Spreadsheet Software

,

Microsoft Visual C#.Net

Participating Experts
1
Points
500
Comments
11

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Encoding
    Hi, I have a web page written in asp,VBScipt and JavaScript. I want to force the user to work with special encoding when he enter my site ("Western European (ISO)"). How can I do it? I don't want to change the site encoding but to change the user Encoding Setting w...
  2. encoding
    dear all, transforming xsl + xml generate ???? or unwanted character for not english language. I tried both statment in xsl file but nor work: <?xml version="1.0" encoding="iso-8859-1" ?> <?xml version="1.0" encoding="windows-125...
  3. inserting  encoding="ISO-8859-1"
    Hi experts, Do you know how i can get encoding="ISO-8859-1" at the top of my xml document, so that it reads <?xml version="1.0" encoding="ISO-8859-1" ?> TaxWriter = new XmlTextWriter(strFileName,System.Text.Encoding.ASCII); thanks
  4. iso-8859-1 encoding
    hi experts, how to write below java code in C#? i could not find the iso-8859-1 encoder in .net. please help...its urgent... static String ENCODING = "iso-8859-1"; String s = new String(Base64.decode("abc123"), ENCODING); any help would be appreciated. ...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: abelPosted on 2009-08-31 at 09:01:00ID: 25223879

The default is the default for the current system. For US based systems, that is Windows-1252. However, Excel shouldn't have trouble with UTF8 or UTF16 (Encoding.Unicode) either (but UTF7 or UTF32 are really out, don't use them).

 

by: toshi_Posted on 2009-09-01 at 01:51:26ID: 25229566

I tried Unicode and Windows-1252, witch are not in the given list of tried encoding, but no matter, Excel 2007 don't recognise such letters as "é". Witch encoding  should I use with a swiss-french or european system?

 

by: abelPosted on 2009-09-01 at 02:25:00ID: 25229709

If you don't specify an encoding at all, the default should be used (this is different then Encoding.Default). For French, the normal encoding on Windows systems is Windows-1252. Other encodings that are well-suited and often used for French are ISO-8859-1 and ISO-8859-15 (with euro and Y+diaeresis).

If your é does not look good in Excel, how does it look? Can you give a small cut-out screenshot? You can also try it the other way around: save a file as CSV with these characters in it and then read it back in, does that work? If it does, can you post the file as attachment here, then I can tell you what encoding to use.

-- Abel --

 

by: abelPosted on 2009-09-01 at 02:29:03ID: 25229725

Looking again at your code, I think that something else maybe the problem. You are not exporting as CSV at all. Instead, you are using a trick, you give the name and headers for excel and then you output html. Try the same trick with the proper headers, and especially, include the following, which must match your encoding (use UTF8 for best coverage):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html  xmlns="http://www.w3.org/1999/xhtml" >
<head>
<meta http-equiv="Content-Type" content="text/csv; charset=utf-8" /> 
</head>
<body>
... your table data
</body>
</html>
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:

Select allOpen in new window

 

by: toshi_Posted on 2009-09-01 at 04:24:53ID: 25230335

I tried ISO-8859-15 encoding, but always the same problem. The CSV file directly created works (test.csv in attachement). I send you also a screenshot of a UTF-8 CSV document.

The code export in Excel 2003 HTML format. This part of the code is working well. But it also tries to export in CSV for Excel 2007 (see GiveCSSResponse).

 

by: abelPosted on 2009-09-01 at 04:58:15ID: 25230559

I'm not surprised that other encodings do not work. That follows from your earlier reports.

The screenshot is clear: Excel reads it in as if it is ISO-8859-1 (or windows-1252) and that changes the letters into double letters for UTF8. What surprises me is that when you use the windows-1252 encoding, that it doesn't work.

What misses in your code is the CharSet, this should be "utf-8" (or another corresponding charset).

What also misses is what I said in my last comment: try adding correct HTML headers for the output, which may help the guessing game of Excel, which is currently apparently off.

Finally, check whether the HeaderEncoding and the ContentEncoding match and are the same.

-- Abel --

 

by: toshi_Posted on 2009-09-01 at 07:32:21ID: 25231973

I put your http header in the front code of my CSV-generating page. I tried to use ISO-8859-1 and windows-1252 with a CharSet of "utf-8", but the problem persists. Normaly, I should read the "é" char directly with for exemple the wordpad, but it gives me a "�" instead (see attached file).

 

by: abelPosted on 2009-09-01 at 09:03:29ID: 25232970

> I tried to use ISO-8859-1 and windows-1252 with a CharSet of "utf-8",

nono, I meant, quote: "or another corresponding charset", be exactly equal. So, windows-1252 with a charset of windows-1252. That must be followed by an HTML header with the same charset.

> Normaly, I should read the "é" char

I know. What you are creating is a UTF-8 file and what Excel is reading is a windows-1252 file. The file you have send here is that same file, saved again as CSV, hence that the encoding contains even more oddities.

The encoding must be the same on all ends for this to work. As long as that is not the case, it will not work.

I am under the impression that you first save the file to disk and then you open it in Excel. Is that correct?

From reports it seems that you need to add the BOM. It is a bug of Microsoft. Unfortunately, the current method for creating the CSV does not allow to add the BOM manually. http://www.jaanuskase.com/en/2006/01/csv_encoding_vs_excel.html

 

by: abelPosted on 2009-09-01 at 09:06:11ID: 25233002

Ah, something else I noticed with your code, all of a sudden, you are apparently not clearing the headers. It didn't occur to me earlier. But just Clear does not clear the headers. Use ClearHeaders for that. Don't think this will help, but you can try.

When you view your data without the content-disposition inside a browser, how does it look, is the é showing up correctly?

 

by: abelPosted on 2009-09-01 at 09:19:23ID: 25233122

Ok, if somehow we cannot manage to get all encodings equal, or if we are somehow blocked by Microsoft Excel bugs, one must try other approaches. Try the following (I cannot try it, but I tested it nonetheless):

1. Use Clear and ClearHeaders
2. Set all places where you have an encoding or a charset etc to utf-8
3. As very first statement, use the line in the code section
4. Do what you normally do

This will force a BOM (byte order mark). This is not necessary, but Microsoft Office products are famous to ignore UTF8 when it clearly is, and starting out with this unique three bytes (EF BB BF) hopefully forces the encoding on Excel. See also the link above which brought me to this idea.

PS: you are writing HTML, which is not CSV which can be the reason for your failure, too. Instead, use the normal Excel extension and mime type "application/vnd.ms-excel", as a last resort.


Response.ClearContent();
Response.ClearHeaders();
Response.ContentEncoding = Encoding.UTF8;
Response.HeaderEncoding = Encoding.UTF8;
Response.AddHeader("Content-Disposition", "filename=" + theCommunity_.Db_name + "_ExportCSVContainersStatusLevels.csv");
Response.Charset = "utf-8";
Response.ContentType = "text/csv";
 
// force UTF8 as very first write statement
Response.BinaryWrite(Encoding.UTF8.GetPreamble());
 
// write normal
Response.Write(GenerateCSVWithAllContainersLevels().ToString());
Response.End();
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:

Select allOpen in new window

 

by: toshi_Posted on 2009-09-04 at 07:33:17ID: 25260073

thank you very much for all the interest,
after trying different solutions,
we decide to change to xml - xls for the file generation.

you did not come with the solution but you help us on understand that this way would never work,
as a matter of fact i allow you all the points.



20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...