ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 效率神器,一键搞定繁琐工作
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
让更多数据处理,一键完成 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 4161|回复: 6

请教高手:怎样上传word文档?

[复制链接]

TA的精华主题

TA的得分主题

发表于 2005-9-11 10:07 | 显示全部楼层 |阅读模式
我想将编辑好的word文档(即当前打开的文档)上传到服务器,请问如何实现将文档名,路径及文档本身上传到服务器(另一台机器)的数据库中?谢谢赐教!

TA的精华主题

TA的得分主题

 楼主| 发表于 2005-9-13 21:08 | 显示全部楼层
真的很想知道怎样实现的?先谢谢了

TA的精华主题

TA的得分主题

发表于 2005-9-13 21:21 | 显示全部楼层

1、什么数据库?

2、上传的方式多,是FTP、HTTP、还是直接用ADODB保存?

3、(实现将文档名,路径及文档本身上传到服务器(另一台机器)的数据库中),则,路径是否要包含当前机器名?是否要包含当前机器上该文件夹的绝对路径?

你不讲清楚,别人想帮你也没法帮。

TA的精华主题

TA的得分主题

发表于 2005-9-14 08:32 | 显示全部楼层

推荐使用xmlhttp方法,把word文档经base64编码,存到一个xml文件中,使用xmlhttp传到服务器,直接存到数据库,使用时解析出来。至于文件名等作为一个字段存到数据库,与正文对应好就行了。这种方式适用于http方式上传,不知你用什么写程序,下面给出vb的例子作参考:

Option Explicit Dim oDoc As DOMDocument Dim DOCINPATH As String Dim XMLOUTPATH As String Dim DOCOUTPATH As String

Public Function sentxml(ByVal xmlfile As String, ByVal url As String, xmlname As String) As Integer '''''''''''''''''''''''''''''''''''''''''''' 'Dim conn As New ADODB.Connection 'Dim rs As New ADODB.Recordset 'Dim rs2 As New ADODB.Recordset 'Dim rs3 As New ADODB.Recordset 'Dim conn2 As New ADODB.Connection 'conn.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=test;Data Source=TTINFO" 'conn.Open 'conn.CursorLocation = adUseClient 'rs.ActiveConnection = conn 'rs.Open "select * from img where id=100" 'Dim da As Variant 'da = rs.Fields("img") '''''''''''''''''''''''''''''''''''''''''''''''''''''' Dim oEle As IXMLDOMElement Dim oRoot As IXMLDOMElement Dim oNode As IXMLDOMNode 'DOCINPATH = App.Path & xmlfile XMLOUTPATH = App.Path & "\" & xmlname '"\XmlOuput.xml" Call ReleaseObjects Set oDoc = New DOMDocument oDoc.resolveExternals = True '' Create processing instruction and document root Set oNode = oDoc.createProcessingInstruction("xml", "version='1.0'") Set oNode = oDoc.insertBefore(oNode, oDoc.childNodes.Item(0)) '' Create document root Set oRoot = oDoc.createElement("Root") Set oDoc.documentElement = oRoot oRoot.setAttribute "xmlns:dt", "urn:schemas-microsoft-com:datatypes"

'' Add a few simple nodes with different datatypes Set oNode = oDoc.createElement("Document") oNode.Text = "Demo" oRoot.appendChild oNode Set oNode = oDoc.createElement("CreateDate") oRoot.appendChild oNode Set oEle = oNode '' Use DataType so MSXML will validate the data type oEle.dataType = "date" oEle.nodeTypedValue = Now Set oNode = oDoc.createElement("bgColor") oRoot.appendChild oNode Set oEle = oNode '' Use DataType so MSXML will validate the data type oEle.dataType = "bin.hex" oEle.Text = &HFFCCCC Set oNode = oDoc.createElement("Data") oRoot.appendChild oNode Set oEle = oNode '' Use DataType so MSXML will validate the data type oEle.dataType = "bin.base64" '' Read in the data oEle.nodeTypedValue = ReadBinData(xmlfile) '' Save xml file oDoc.Save XMLOUTPATH '********************************************** Dim strA As String, szFile As String, m_szUpFile As String 'm_szUpFile = "http://localhost/sign/getupFile.asp?penid=aaa" 'server端的ASP接受程序 'MsgBox XMLOUTPATH & " is created for you." Dim xmlHttp As New MSXML2.xmlHttp xmlHttp.Open "POST", url, False xmlHttp.setRequestHeader "CONTENT-TYPE", "text/xml" xmlHttp.send oDoc ' 显示服务器返回的信息 Debug.Print xmlHttp.responseText If xmlHttp.Status = 200 Then sentxml = 1 Else sentxml = 0 End If 'MsgBox sentxml Set xmlHttp = Nothing Set oDoc = Nothing

End Function

Function ReadBinData(ByVal strFileName As String) As Variant Dim lLen As Long Dim iFile As Integer Dim arrBytes() As Byte Dim lCount As Long Dim strOut As String

''Read from disk iFile = FreeFile() Open strFileName For Binary Access Read As iFile lLen = FileLen(strFileName) ReDim arrBytes(lLen - 1) Get iFile, , arrBytes Close iFile

ReadBinData = arrBytes End Function ' 'Private Sub WriteBinData(ByVal strFileName As String) ' Dim iFile As Integer ' Dim arrBuffer() As Byte ' Dim oNode As IXMLDOMNode ' ' If Not (oDoc Is Nothing) Then ' ''' Get the data ' Set oNode = oDoc.documentElement.selectSingleNode("/Root/Data") ' ''' Make sure you use a byte array instead of variant ' arrBuffer = oNode.nodeTypedValue ' ''' Write to disk ' ' iFile = FreeFile() ' Open strFileName For Binary Access Write As iFile ' Put iFile, , arrBuffer ' Close iFile ' ' End If ' 'End Sub ' 'Private Sub Command2_Click() ' ' DOCOUTPATH = App.Path & "\DocOutput.jpg" ' ' Set oDoc = New DOMDocument ' ' If oDoc.Load(XMLOUTPATH) = True Then ' '' Save the Doc as another file ' WriteBinData DOCOUTPATH ' ' MsgBox DOCOUTPATH & " is created for you." ' Else ' MsgBox oDoc.parseError.reason ' End If 'End Sub

Private Sub Form_Unload(Cancel As Integer) ReleaseObjects End Sub

Private Sub ReleaseObjects() Set oDoc = Nothing End Sub

以上代码实现了读取文件、上传文件,下面是服务器端解析用的asp文件:

贴不上了,见下一个贴子

TA的精华主题

TA的得分主题

发表于 2005-9-14 08:33 | 显示全部楼层

服务器端:

<% set conn=server.CreateObject("ADODB.connection") connstr="driver={Microsoft Access Driver (*.mdb)};dbq="&server.MapPath("db\db1.mdb") conn.open connstr pen=request.querystring("penid") set rs = server.CreateObject("ADODB.Recordset") rs.Open "select * from sign where signpen=" & "'" & pen & "'" & " and signflag='0'",conn,3,3 docid=rs(2) uuname=rs(3) spen=rs(5) '************************************************************************ Dim ado_stream Dim oXmlDom Dim xml_file1,m_szpath dim dataimg Set oXMLDoc = Server.CreateObject("Microsoft.XMLDOM") szPath=server.mappath("getupfile.asp") nPos=instrRev(szPath ,"\") m_szPath=left(szPath,nPos) response.write szPath oXMLDoc.load request szNow=year(now()) & month(now()) & day(now()) & hour(now()) & minute(now()) & second(now()) szpath=m_szPath & "upfile.xml" oXMLDoc.save szPath ' 创建 Stream 对象 Set ado_stream = Server.CreateObject("ADODB.Stream") ' 读出包含二进制数据的节点 Set xml_file1 = oXMLDoc.selectSingleNode("/Root/Data") 'dataimg=xml_file1.nodeTypedValue ' 打开Stream对象,把数据存入其中 ado_stream.Type = 1 ' 1=adTypeBinary ado_stream.open ado_stream.Write xml_file1.nodeTypedValue ' 文件存盘 szPath=m_szpath &"images\" &docid&uuname & ".gif" '存储文件 sspa=docid & uuname & ".gif" ado_stream.SaveToFile szpath, 2 ' 2=adSaveCreateOverWrite response.write szpath rs.addnew rs(1)=sspa rs(2)=docid rs(3)=uuname rs(5)=spen rs(6)=1 rs.update rs.close conn.execute "delete * from sign where signpen=" & "'" & pen & "'" & " and signflag='0'" ado_stream.Close ' 销毁对象 set conn=nothing Set ado_stream = Nothing Set xmlDoc = Nothing %>

TA的精华主题

TA的得分主题

发表于 2005-9-14 21:16 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助
仔细看了一下,前面上传时使用的是SQL Server后面读时使用的是Access,不如使用“化境上传类”或“风声上传类”的代码简洁。

TA的精华主题

TA的得分主题

 楼主| 发表于 2005-9-21 21:42 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助
多谢你们的帮忙!
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-11-15 17:19 , Processed in 0.036651 second(s), 10 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表