Tag Archives: Excel

Export to Excel in SharePoint Application Page doesn’t work on second time

The cause for this behavior is that there is a flag (named _spFormOnSubmitCalled) in SharePoint which prevents double form submition. This flag is set when the form is submitted and clear when the response is received.

However when exporting the response is redirected and the page is not updated, thus the flag is not cleared and page’s postbacks are blocked.

In order to workaround this behavior you should manually clear the flag when exporting. This can be achieve, for example in export button’s client click function similar to the following:

MyExportButton.OnClientClick = “_spFormOnSubmitCalled = false;”

Setting the _spFormOnSubmitCalled to false is actually what MS Ajax is doing when an ajax request is made thus I suspect there should be not implication using such approach.

About the removing spFormOnSubmitWrapper function call, you may instead set _spSuppressFormOnSubmitWrapper variable to true, which can be done conditionally only where needed by outputting similar to the following script:

_spBodyOnLoadFunctionNames.push(“supressSubmitWraper”);
function supressSubmitWraper()
{
_spSuppressFormOnSubmitWrapper = true;
}

来源: http://www.telerik.com/community/forums/aspnet-ajax/grid/export-to-excel-in-sharepoint-application-page.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