Tag Archives: 代码

在Repeater中添加换页符

1
2
3
4
5
6
7
protected void ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if ((e.Item.ItemType.Equals(ListItemType.Item) || e.Item.ItemType.Equals(ListItemType.AlternatingItem)) && (e.Item.ItemIndex + 1) % ProductsPerPage == 0)
{
e.Item.Controls.Add(new LiteralControl("<tr><td class=\"PageBreak\" ></td></tr>"));
}
}

来源: http://weblogs.asp.net/dennisthemenace/archive/2008/01/25/insertion-of-a-page-break-in-a-repeater.aspx

Styling Excel cells with mso-number-format

mso-number-format:”0″ NO Decimals
mso-number-format:”0\.000″ 3 Decimals
mso-number-format:”\#\,\#\#0\.000″ Comma with 3 dec
mso-number-format:”mm\/dd\/yy” Date7
mso-number-format:”mmmm\ d\,\ yyyy” Date9
mso-number-format:”m\/d\/yy\ h\:mm\ AM\/PM” D -T AMPM
mso-number-format:”Short Date” 01/03/1998
mso-number-format:”Medium Date” 01-mar-98
mso-number-format:”d\-mmm\-yyyy” 01-mar-1998
mso-number-format:”Short Time” 5:16
mso-number-format:”Medium Time” 5:16 am
mso-number-format:”Long Time” 5:16:21:00
mso-number-format:”Percent” Percent – two decimals
mso-number-format:”0%” Percent – no decimals
mso-number-format:”0\.E+00″ Scientific Notation
mso-number-format:”\@” Text
mso-number-format:”\#\ ???\/???” Fractions – up to 3 digits (312/943)
mso-number-format:”\0022£\0022\#\,\#\#0\.00″ £12.76
mso-number-format:”\#\,\#\#0\.00_ \;\[Red\]\-\#\,\#\#0\.00\ “ 2 decimals, negative numbers in red and signed
(1.56   -1.56)

用法举例:

当我们用<%@page contentType=”application/vnd.ms-excel; charset=UTF-8″%>的方法导出网页文件为excel时,如果导出的数据中有数字以0开头,则该0会被省略,为了保留这个处于首位的0,可以在表格的style中加入:

style=’mso-number-format:”\@”;’

这样的话,导出的该表格中首位为0的数字就会将该0保留啦!

来源: http://blog.sina.com.cn/s/blog_5a010cd10100c3gs.html

SQL脚本 — 行变列

create table aaa
(
col nvarchar(10)
)

insert into aaa
select 1
union
select 2
union
select 3

declare @sql varchar(8000)
set @sql=’select ‘
select  @sql=@sql+’max(case col when ”’+ col +”’ then col end) + ”,” + ‘
from (select distinct col from aaa)  a
set @sql=left(@sql,len(@sql)-1)

set @sql=@sql+’  from aaa’
–print @sql
exec(@sql)

drop table aaa