Thursday, June 17, 2010

Excel all Worksheet Column Case Change Macro

Sub UpCase()

Dim dbSheet As Worksheet
Dim LastRowColC
For i = 1 To Worksheets.Count
    Set dbSheet = Worksheets(i)
    LastRowColC = dbSheet.Range("B" + CStr(dbSheet.Rows.Count)).End(xlUp).Row
    For j = 1 To LastRowColC
        dbSheet.Cells(j, "B").Value = StrConv(dbSheet.Cells(j, "B").Value, vbUpperCase)
    Next j
Next i
End Sub

Friday, May 7, 2010

Read CSV with oledb to dataset - datatable

string csvDirectory = Server.MapPath("~/media/");
        string CsvFile = "SampleDirectory.csv";
        DataSet ds = new DataSet();
        OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + csvDirectory + ";Extended Properties='text;HDR=Yes;FMT=Delimited'");
        OleDbDataAdapter ExcelAdapter = new OleDbDataAdapter("SELECT * FROM " + CsvFile, con);
        con.Open();
        ExcelAdapter.Fill(ds);
        con.Close();
        GridView1.DataSource = ds;
        GridView1.DataBind();

Resize Image with javascript

function resizeImageByWidth(img,MaxWidth) {
    try {
        if (img != null && img.src != "") {
            img.attributes.removeNamedItem("width");
            img.attributes.removeNamedItem("height");

            var oW = img.width;
            var oH = img.height;

            if (oW > MaxWidth) {
                var rW = parseFloat(oW) / parseFloat(MaxWidth);
                img.width = parseInt(oW / rW);
                img.height = parseInt(oH / rW);
            }
        }
    }
    catch (ex) {
        img.width = MaxWidth;
    }
}

function resizeImage(img, maxHeight, MaxWidth) {
    try {
        if (img != null && img.src != "") {
            img.attributes.removeNamedItem("width");
            img.attributes.removeNamedItem("height");

            var oW = img.width;
            var oH = img.height;

            if (oW > MaxWidth || oH > maxHeight) {
                var rW = parseFloat(oW) / parseFloat(MaxWidth);
                var rH = parseFloat(oH) / parseFloat(maxHeight);
                var ratio = Math.max(rW, rH);
                img.width = parseInt(oW / ratio);
                img.height = parseInt(oH / ratio);
            }
        }
    }
    catch (ex) {
        img.height = maxHeight;
        img.width = MaxWidth;
    }
}
To use in the image just add onload event event on image


any size is given automatically removed.