如何清除word,excel粘贴的样式?请高手指教

li_net 2006-08-13 11:47:35
我想把word,excel等内容贴到输入框里,但,无法清除其多余的样式,导致提交时出现[Microsoft][ODBC SQL Server Driver][SQL Server]第 1 行: 'Times' 附近有语法错误。
提交的从word粘贴的内容如下:
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 32pt; LINE-HEIGHT: 28pt; mso-line-height-rule: exactly; mso-char-indent-count: 2.0; mso-char-indent-size: 16.0pt"><SPAN style="FONT-SIZE: 16pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">几方面的。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 16pt"><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 28pt; mso-line-height-rule: exactly"><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-SIZE: 16pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"></SPAN></B><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US style="FONT-SIZE: 16pt"><o:p></o:p></SPAN></B> </P>
<P> </P>

请高手指教,谢谢!
...全文
821 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
li_net 2006-08-18
  • 打赏
  • 举报
回复
谢谢jiangsh100(著名菜鸟) ,我把插入数据库的“'”去掉了,导入数据不会出错了,但那些样式还是过滤不掉。
jiangsh100 2006-08-17
  • 打赏
  • 举报
回复
不妨都试试
// 清除WORD冗余格式并粘贴
function cleanAndPaste( html ) {
// Remove all SPAN tags
html = html.replace(/<\/?SPAN[^>]*>/gi, "" );
// Remove Class attributes
html = html.replace(/<(\w[^>]*) class=([^ |>]*)([^>]*)/gi, "<$1$3") ;
// Remove Style attributes
html = html.replace(/<(\w[^>]*) style="([^"]*)"([^>]*)/gi, "<$1$3") ;
// Remove Lang attributes
html = html.replace(/<(\w[^>]*) lang=([^ |>]*)([^>]*)/gi, "<$1$3") ;
// Remove XML elements and declarations
html = html.replace(/<\\?\?xml[^>]*>/gi, "") ;
// Remove Tags with XML namespace declarations: <o:p></o:p>
html = html.replace(/<\/?\w+:[^>]*>/gi, "") ;
// Replace the  
html = html.replace(/ /, " " );
// Transform <P> to <DIV>
var re = new RegExp("(<P)([^>]*>.*?)(<\/P>)","gi") ; // Different because of a IE 5.0 error
html = html.replace( re, "<div$2</div>" ) ;

insertHTML( html ) ;
}
jiangsh100 2006-08-17
  • 打赏
  • 举报
回复
是从编辑器里面拷出来的
我没试过
你试试吧
// 粘贴时自动检测是否来源于Word格式
function onPaste() {
if (sCurrMode=="VIEW") return false;

if (sCurrMode=="EDIT"){
var sHTML = GetClipboardHTML() ;
if (config.AutoDetectPasteFromWord && BrowserInfo.IsIE55OrMore) {
var re = /<\w[^>]* class="?MsoNormal"?/gi ;
if ( re.test(sHTML)){
if ( confirm( "你要粘贴的内容好象是从Word中拷出来的,是否要先清除Word格式再粘贴?" ) ){
cleanAndPaste( sHTML ) ;
return false ;
}
}
}
eWebEditor.document.selection.createRange().pasteHTML(sHTML) ;
return false;
}else{
eWebEditor.document.selection.createRange().pasteHTML(HTMLEncode( clipboardData.getData("Text"))) ;
return false;
}

}
li_net 2006-08-17
  • 打赏
  • 举报
回复
谢谢,不过,可能我表达有问题,我不是指在设计页面时清清word excel的样式,我是指在提交表单后,如何编写一个清除的程序,

请高手指教,谢谢!!!
gnimgnot 2006-08-13
  • 打赏
  • 举报
回复
dreamweaver 命令下拉里

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧