[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

6.7

What is the default encoding off Microsoft Excel 2007?

Asked by toshi_ in .NET Framework 2.x, Microsoft Excel Spreadsheet Software, Microsoft Visual C#.Net

Tags: Microsoft Visual Studio 2005 .NET, Microsoft Excel 2007

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
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:
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
 
    }
}
[+][-]08/31/09 09:01 AM, ID: 25223879Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/01/09 01:51 AM, ID: 25229566Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/01/09 02:25 AM, ID: 25229709Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/01/09 02:29 AM, ID: 25229725Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/01/09 04:24 AM, ID: 25230335Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/01/09 04:58 AM, ID: 25230559Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/01/09 07:32 AM, ID: 25231973Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/01/09 09:03 AM, ID: 25232970Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/01/09 09:06 AM, ID: 25233002Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/01/09 09:19 AM, ID: 25233122Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: .NET Framework 2.x, Microsoft Excel Spreadsheet Software, Microsoft Visual C#.Net
Tags: Microsoft Visual Studio 2005 .NET, Microsoft Excel 2007
Sign Up Now!
Solution Provided By: abel
Participating Experts: 1
Solution Grade: A
 
[+][-]09/04/09 07:33 AM, ID: 25260073Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091021-EE-VQP-81 - Hierarchy / EE_QW_3_20080625