Background color of cell in Excel
Solved/Closed
Related:
- Background color of cell in Excel
- Notepad++ background color - Guide
- Viber background - Guide
- Number to words in excel - Guide
- Wechat background - Guide
- Color coding of rj45 - Guide
3 responses
The following Javascript code will help you change the background-color of your web-page automatically and at a time-interval (in milli-seconds) as specified in the code.
<head>
<script type="text/javascript" language="javascript">
/* Method To Generate Random Numbers Between "0-255" for RGB Color-code Format & Assign To Body-Backgrond-Style */
function bgDisco()
{
var x =Math.round(255*Math.random());
var num1 =getHex(x);
var y =Math.round(255*Math.random());
var num2 =getHex(y);
var z =Math.round(255*Math.random());
var num3 =getHex(z);
document.body.style.background="#"+num1+num2+num3;
setTimeout("bgDisco()",1000);
}
/* Method To Convert Decimal To Hexadecimal */
function getHex(dec)
{
var hexArray = new Array( "0", "1", "2", "3","4", "5", "6", "7","8", "9", "A", "B","C", "D", "E", "F" );
var code1 = Math.floor(dec / 16);
var code2 = dec - code1 * 16;
var decToHex = hexArray[code2];
return (decToHex);
}
</script>
</head>
Eliza
<head>
<script type="text/javascript" language="javascript">
/* Method To Generate Random Numbers Between "0-255" for RGB Color-code Format & Assign To Body-Backgrond-Style */
function bgDisco()
{
var x =Math.round(255*Math.random());
var num1 =getHex(x);
var y =Math.round(255*Math.random());
var num2 =getHex(y);
var z =Math.round(255*Math.random());
var num3 =getHex(z);
document.body.style.background="#"+num1+num2+num3;
setTimeout("bgDisco()",1000);
}
/* Method To Convert Decimal To Hexadecimal */
function getHex(dec)
{
var hexArray = new Array( "0", "1", "2", "3","4", "5", "6", "7","8", "9", "A", "B","C", "D", "E", "F" );
var code1 = Math.floor(dec / 16);
var code2 = dec - code1 * 16;
var decToHex = hexArray[code2];
return (decToHex);
}
</script>
</head>
Eliza
The following Javascript code will help you change the background-color of your web-page automatically and at a time-interval (in milli-seconds) as specified in the code.
<head>
<script type="text/javascript" language="javascript">
/* Method To Generate Random Numbers Between "0-255" for RGB Color-code Format & Assign To Body-Backgrond-Style */
function bgDisco()
{
var x =Math.round(255*Math.random());
var num1 =getHex(x);
var y =Math.round(255*Math.random());
var num2 =getHex(y);
var z =Math.round(255*Math.random());
var num3 =getHex(z);
document.body.style.background="#"+num1+num2+num3;
setTimeout("bgDisco()",1000);
}
/* Method To Convert Decimal To Hexadecimal */
function getHex(dec)
{
<head>
<script type="text/javascript" language="javascript">
/* Method To Generate Random Numbers Between "0-255" for RGB Color-code Format & Assign To Body-Backgrond-Style */
function bgDisco()
{
var x =Math.round(255*Math.random());
var num1 =getHex(x);
var y =Math.round(255*Math.random());
var num2 =getHex(y);
var z =Math.round(255*Math.random());
var num3 =getHex(z);
document.body.style.background="#"+num1+num2+num3;
setTimeout("bgDisco()",1000);
}
/* Method To Convert Decimal To Hexadecimal */
function getHex(dec)
{
http://www.mindfiresolutions.com/...
Please look at the below code, I wrote it for formatting excel cells. Its not as fast as u may think of, since it happens on client side. other disadvanatage is, the client needs to have excel on the machine, otherwise it will fail...
function CreateExcelSheet()
{
var x=dataTable.rows
var xls = new ActiveXObject("Excel.Application")
xls.visible = true
var newBook = xls.Workbooks.Add
newBook.Worksheets.Add;
var row,col,rangRow, rangCol;
var colSelector = document.getElementById("colSelector").value;
row = x[0].cells.length;
col = x.length;
for (i = 0; I < x.length; i++)
{
var y = x[i].cells
for (j = 0; j < y.length; j++)
{
xls.Cells( i+1, j+1).Value = y[j].innerText;
xls.ActiveCell.EntireRow.Font.Bold = true;
xls.ActiveCell.EntireRow.Font.ColorIndex = 2;
}
}
xls.Cells.Select
xls.Cells.EntireColumn.AutoFit
if(row == 7)
rangRow = "A1"+":"+"G"+"1";
else if(row == 8)
rangRow = "A1"+":"+"H"+"1";
else if(row == 9)
rangRow = "A1"+":"+"I"+"1";
else if(row == 10)
rangRow = "A1"+":"+"J"+"1";
else if(row == 11)
rangRow = "A1"+":"+"K"+"1";
xls.range(rangRow).Select;
xls.Selection.Interior.ColorIndex = 53;
//xls.Selection.Interior.Pattern = xlSolid;
for(k=2; k<=col;k++)
{
if(colSelector == 'ticker')
{
rangCol = "A"+k+":"+"A"+k;
}
else if(colSelector == 'fund')
{
rangCol = "A"+k+":"+"A"+k;
}
else if(colSelector == 'companyName')
{
rangCol = "B"+k+":"+"B"+k;
}
else if(colSelector == 'coupon')
{
rangCol = "C"+k+":"+"C"+k;
}
else if(colSelector == 'maturity')
{
rangCol = "D"+k+":"+"D"+k;
}
else if(colSelector == 'numshares')
{
rangCol = "E"+k+":"+"E"+k;
}
else if(colSelector == 'notional')
{
rangCol = "F"+k+":"+"F"+k;
}
else if(colSelector == 'securityType')
{
rangCol = "G"+k+":"+"G"+k;
}
else if(colSelector == 'cusip')
{
rangCol = "H"+k+":"+"H"+k;
}
else if(colSelector == 'putcall')
{
rangCol = "I"+k+":"+"I"+k;
}
else if(colSelector == 'filingDate')
{
rangCol = "J"+k+":"+"J"+k;
}
else if(colSelector == 'positionDate')
{
rangCol = "K"+k+":"+"K"+k;
}
xls.range(rangCol).Select;
if(k%2!=0)
xls.Selection.Interior.ColorIndex = 36;
else
xls.Selection.Interior.ColorIndex = 15;
//xls.Selection.Interior.Pattern = xlSolid;
}
newBook.Worksheets(1).Name="13F Filing";
newBook.Worksheets(1).SaveAs("h:\\java\\13F Filing.xls");
}
function CreateExcelSheet()
{
var x=dataTable.rows
var xls = new ActiveXObject("Excel.Application")
xls.visible = true
var newBook = xls.Workbooks.Add
newBook.Worksheets.Add;
var row,col,rangRow, rangCol;
var colSelector = document.getElementById("colSelector").value;
row = x[0].cells.length;
col = x.length;
for (i = 0; I < x.length; i++)
{
var y = x[i].cells
for (j = 0; j < y.length; j++)
{
xls.Cells( i+1, j+1).Value = y[j].innerText;
xls.ActiveCell.EntireRow.Font.Bold = true;
xls.ActiveCell.EntireRow.Font.ColorIndex = 2;
}
}
xls.Cells.Select
xls.Cells.EntireColumn.AutoFit
if(row == 7)
rangRow = "A1"+":"+"G"+"1";
else if(row == 8)
rangRow = "A1"+":"+"H"+"1";
else if(row == 9)
rangRow = "A1"+":"+"I"+"1";
else if(row == 10)
rangRow = "A1"+":"+"J"+"1";
else if(row == 11)
rangRow = "A1"+":"+"K"+"1";
xls.range(rangRow).Select;
xls.Selection.Interior.ColorIndex = 53;
//xls.Selection.Interior.Pattern = xlSolid;
for(k=2; k<=col;k++)
{
if(colSelector == 'ticker')
{
rangCol = "A"+k+":"+"A"+k;
}
else if(colSelector == 'fund')
{
rangCol = "A"+k+":"+"A"+k;
}
else if(colSelector == 'companyName')
{
rangCol = "B"+k+":"+"B"+k;
}
else if(colSelector == 'coupon')
{
rangCol = "C"+k+":"+"C"+k;
}
else if(colSelector == 'maturity')
{
rangCol = "D"+k+":"+"D"+k;
}
else if(colSelector == 'numshares')
{
rangCol = "E"+k+":"+"E"+k;
}
else if(colSelector == 'notional')
{
rangCol = "F"+k+":"+"F"+k;
}
else if(colSelector == 'securityType')
{
rangCol = "G"+k+":"+"G"+k;
}
else if(colSelector == 'cusip')
{
rangCol = "H"+k+":"+"H"+k;
}
else if(colSelector == 'putcall')
{
rangCol = "I"+k+":"+"I"+k;
}
else if(colSelector == 'filingDate')
{
rangCol = "J"+k+":"+"J"+k;
}
else if(colSelector == 'positionDate')
{
rangCol = "K"+k+":"+"K"+k;
}
xls.range(rangCol).Select;
if(k%2!=0)
xls.Selection.Interior.ColorIndex = 36;
else
xls.Selection.Interior.ColorIndex = 15;
//xls.Selection.Interior.Pattern = xlSolid;
}
newBook.Worksheets(1).Name="13F Filing";
newBook.Worksheets(1).SaveAs("h:\\java\\13F Filing.xls");
}