May 2007

You are currently browsing the monthly archive for May 2007.

There’s an article at codeproject.com which transform a .NET DataSet to an XML Spreadsheet document which can be opened in Microsoft Excel. Unfortunately the code doesn’t seem to be generate valid XML, at least not for Excel. I’ve modified it but didn’t use some parts of if (e.g. I don’t use the time formatting at the moment so I stripped out all the styles using it,…).

Here’s the new code:

[code lang="csharp"] ///

/// Exports data in dataset to excel. /// Original code: http://www.codeproject.com/dotnet/exporttoexcel.asp /// public class excelexport { public static void exporttoexcel(dataset source, string filename) {

system.io.streamwriter exceldoc;

exceldoc = new system.io.streamwriter(filename);
const string startexcelxml = 
  "<?xml version=\"1.0\"?>\r\n" +
  "<?mso-application progid=\"excel.sheet\"?>\r\n" +
  "<workbook xmlns=\"urn:schemas-microsoft-com:office:spreadsheet\"\r\n" +
  " xmlns:o=\"urn:schemas-microsoft-com:office:office\"\r\n" +
  " xmlns:x=\"urn:schemas-microsoft-com:office:excel\"\r\n" +
  " xmlns:ss=\"urn:schemas-microsoft-com:office:spreadsheet\">\r\n" +
  " <styles>\r\n" +
  "  <style ss:id=\"default\" ss:name=\"normal\">\r\n" +
  "   <alignment ss:vertical=\"bottom\"/>\r\n" +
  "   <borders/>\r\n" +
  "   <font/>\r\n" +
  "   <interior/>\r\n" +
  "   <numberformat/>\r\n" +
  "   <protection/>\r\n" +
  "  </style>\r\n" +
  "  <style ss:id=\"bold\">\r\n" +
  "   <font x:family=\"swiss\" ss:bold=\"1\"/>\r\n" + 
  "  </style>\r\n" + 
  " </styles>\r\n";
const string endexcelxml = "</workbook>";

int rowcount = 0;
int sheetcount = 1;

exceldoc.write(startexcelxml);
exceldoc.write("<worksheet ss:name=\"sheet" + sheetcount + "\">\r\n");
exceldoc.write("<table>\r\n");

for (int x = 0; x < source.tables[0].columns.count; x++)
{
  int width = source.tables[0].columns[x].columnname.length * 8;
  exceldoc.write("<column ss:width=\"" + width + "\"/>\r\n");
}

exceldoc.write("<row ss:styleid=\"bold\">\r\n");

for (int x = 0; x < source.tables[0].columns.count; x++)
{
  exceldoc.write("<cell><data ss:type=\"string\">");
  exceldoc.write(source.tables[0].columns[x].columnname);
  exceldoc.write("</data></cell>\r\n");
}

exceldoc.write("</row>\r\n");

foreach (datarow x in source.tables[0].rows)
{
  rowcount++;
  //if the number of rows is > 64000 create a new page to continue output
  if (rowcount == 64000)
  {
    rowcount = 0;
    sheetcount++;
    exceldoc.write("</table>\r\n");
    exceldoc.write(" </worksheet>\r\n");
    exceldoc.write("<worksheet ss:name=\"sheet" + sheetcount + "\">\r\n");
    exceldoc.write("<table>\r\n");
  }

  exceldoc.write("<row>\r\n"); //id=" + rowcount + "

  for (int y = 0; y < source.tables[0].columns.count; y++)
  {
    system.type rowtype;
    rowtype = x[y].gettype();
    switch (rowtype.tostring())
    {
      case "system.string":
        string xmlstring = x[y].tostring();
        xmlstring = xmlstring.trim();
        xmlstring = xmlstring.replace("&", "&amp;");
        xmlstring = xmlstring.replace(">", "&gt;");
        xmlstring = xmlstring.replace("<", "&lt;");
        exceldoc.write("<cell><data ss:type=\"string\">");
        exceldoc.write(xmlstring);
        exceldoc.write("</data></cell>\r\n");
        break;
      case "system.datetime":
        //excel has a specific date format of yyyy-mm-dd followed by  
        //the letter 't' then hh:mm:sss.lll example 2005-01-31t24:01:21.000
        //the following code puts the date stored in xmldate 
        //to the format above
        datetime xmldate = (datetime)x[y];
        string xmldatetostring = ""; //excel converted date
        xmldatetostring = xmldate.year.tostring() +
          "-" +
          (xmldate.month < 10 ? "0" +
          xmldate.month.tostring() : xmldate.month.tostring()) +
          "-" +
          (xmldate.day < 10 ? "0" +
          xmldate.day.tostring() : xmldate.day.tostring()) +
          "t" +
          (xmldate.hour < 10 ? "0" +
          xmldate.hour.tostring() : xmldate.hour.tostring()) +
          ":" +
          (xmldate.minute < 10 ? "0" +
          xmldate.minute.tostring() : xmldate.minute.tostring()) +
          ":" +
          (xmldate.second < 10 ? "0" +
          xmldate.second.tostring() : xmldate.second.tostring()) +
          ".000";

        exceldoc.write("<cell><data ss:type=\"datetime\">");
        exceldoc.write(xmldatetostring);
        exceldoc.write("</data></cell>\r\n");
        break;
      case "system.boolean":
        exceldoc.write("<cell><data ss:type=\"string\">");
        exceldoc.write(x[y].tostring());
        exceldoc.write("</data></cell>\r\n");
        break;
      case "system.int16":
      case "system.int32":
      case "system.int64":
      case "system.byte":
        exceldoc.write("<cell><data ss:type=\"number\">");
        exceldoc.write(x[y].tostring());
        exceldoc.write("</data></cell>\r\n");
        break;
      case "system.decimal":
      case "system.double":
        exceldoc.write("<cell><data ss:type=\"number\">");
        exceldoc.write(x[y].tostring());
        exceldoc.write("</data></cell>\r\n");
        break;
      case "system.dbnull":
        exceldoc.write("<cell><data ss:type=\"string\">");
        exceldoc.write("");
        exceldoc.write("</data></cell>\r\n");
        break;
      default:
        xmlstring = x[y].tostring();
        xmlstring = xmlstring.trim();
        xmlstring = xmlstring.replace("&", "&amp;");
        xmlstring = xmlstring.replace(">", "&gt;");
        xmlstring = xmlstring.replace("<", "&lt;");
        xmlstring = xmlstring.replace("\r\n", " - ");
        exceldoc.write("<cell><data ss:type=\"string\">\r\n");
        exceldoc.write(xmlstring);
        exceldoc.write("</data></cell>\r\n");
        break;
      //throw (new exception(rowtype.tostring() + " not handled."));
      }
    }
  exceldoc.write("</row>\r\n");
}

exceldoc.write("</table>\r\n");
exceldoc.write(" </worksheet>\r\n");
exceldoc.write(endexcelxml);
exceldoc.close();

} } [/code]

I suppose that Justin wanted to play around with the shifting operators, because there’s an easier way to convert a number from decimal to hex representation:

[code lang="javascript"] Number.prototype.toHex = function() { return this.toString(16) }

(255).toHex(); //ff [255, 255, 255].invoke(’toHex’).join(”); //ffffff [/code]

iWoz
JavaScript - The Definitive Guide
Object Thinking
The Art of Interactive Design

Got iWoz and JavaScript today via Amazon (sneak peaked into it), Object Thinking is a bit boring at the beginning but overally good and informative (some background infos which save you some googling).

- Monolithic 2-tier Architecture
- 3.3 Million Line C++ ISAPI DLL (150MB binary)
- Hundreds of developers, all working on the same code
- Hitting compiler limits on number of methods per class (!!)

The eBay Architecture

Avc Vet School Reviews Degree Life Experience Credit Teaching Pathos Pantera Medical Mike Karash Siberian Huskis Dog Teacher Recruitment To Work In Us What Is A Rico Case Colbert County School Websites Sharp Copier Arm550n Instructions Online Sacred Heart Church Valley Park Mo New Bet Shows Motor Home Jacks Uk Azesearch Toolbar Remover Free Declaration Of War Britain Sainsbury's Online Groceries Bags Carrier Drivers Ih24 Solf Ngare Dearka Miriallia Haw Laramie Wood Stove Meridian Federal Credit Union Mings Chinses Restaurant Vancouver Shandur Away Meesages Negative Voltages Mid Wife Directory Lakenhearst New Jersey Death Of Jeremy Williams Rjet Online Convert Netscape7 Mail To Outlook Express Debbie Mathis Realty Foxtel Gold Card Irdeto 2 Dream Where We Are Together Lyrics Franchise Homes New Zealand Asymptotic Behaviour Vectra Gym Price Azalea Bridal Snellville Asperger Savant Music Most Played Music Videos Of 2007 Content Management System Homepage Tampa Plastic Surgery Malpractice Fox C6 Arnold Culinary Institute Of Arts Napa Definition And Maladaptive Coping Skills New Found Glory This Disaster Constant Clearing My Throat What Is Alexander Fleming Known For Fusion Adelaide 2007 Crown Of Life Cicero Owasso Oklahoma Newspaper Nederland Town Colorado Murder Mystery Blues Tickets Autoweb Law College In Cedar Rapids Ia Mercury Outboard Impeller Repair Defect Marking Miniature Pinscher Biarritz Rugby Website Ringtones Sony Ericcson Contabilidad Agropecuaria Nephron Functions In The Excretory System Miami Head Hunters Rick Hamm Conctruction Michael Cpa Securities Downtown Denver Congressman Hayes Richmond Surrey England Sailor Star Song Mp3 Demographics Kahului Maui Awnings Boulder Co What Harm Thhing After Tsunami Automatic Speech Recognition Speaker Shower Steam Saunas Shower Steam Safebreastaugment Acid Control Technology Gopher Landscaping Software What Is Corrosion Of Steel Rent A Car Charlotte North Carolina Manufacturing Engineer Want Ads Mens Cologne Or Body Sprays Dees Tyndall Rental Agency Family Fitness Activity Awsm Telemarketing Panama Critica Contact Tv Talk Shows Ctv Rising Sea Levels Pan Flute Tutorial What Is The Coptic Orthodox Church Iga Instituto Gastronomico Argentino Death Guild Burning Man Average Asian Breast Size Colony Of Birchman Estate Investing Keogh Llc Real Music In Johnny English Micheal Young Massage Therapist Sheer Squares Decorative Non-woven Fabric Famous Philosophers On War And Peace Mineral Oil Sterling Ouija Board Stories Palos Verdes Estates Ca Real Estate Construction Renovation Tips Shore Diving In Marathon Key Cu Parking Mindfulness Dc University