在我访问数据库中存储的Excel模板 [英] Storing Excel templates in my Access database

查看:153
本文介绍了在我访问数据库中存储的Excel模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个MS Access数据库的工作,产生一个报告,安省专业工程大学认可委员会。该PEO有他们在MS Excel模板,我要用自己的实际格式。

I am working with an MS Access database to produce a report for the Ontario Professional Engineering University Accreditation board. The PEO have their templates in MS Excel and I MUST use their exact format.

我要输出的Access数据库中的数据的Excel工作表中(很容易),但我想产生一个新的文件时复制其格式。 (我不希望保持一个空的模板文件,每一次复制)。

I want to output the data from the Access DB to the Excel sheet (easy enough), but I want to copy their formatting when producing a new file. (I do NOT want to keep an empty template file and copy it each time).

所以基本上我期待以某种方式保存在code中的模板。 (其他建议,欢迎!)

So essentially I'm looking to somehow store the template in code. (Other suggestions are welcome!)

你们当中有些人会读这一点,认为我是个白痴。但我想是通过的 API code 并存储为数据对象(我希望)某种形式的字符串。

Some of you will read this and think i'm an idiot. But what i tried was to get the data from excel on the MS Clipboard through the API Code and store the DataObject as (i was hoping) some sort of string.

但我不能preserve从原来的MS Excel模板的格式或单元格底纹。

But i could not preserve the formatting or cell shading from the original MS Excel template.

有什么建议?...

推荐答案

您可以通过创建一个包括附件一表存储在数据库中的Excel模板(S)现场

You could store the Excel template(s) within the database by creating a table that includes an Attachment field

创建记录和Excel模板作为附件保存到该记录

creating a record and saving the Excel template as an attachment to that record

,然后使用VBA code这样当你需要一个保存Excel文档到磁盘的新副本:

and then using VBA code like this to save a new copy of the Excel document to disk whenever you need one:

Option Compare Database
Option Explicit

Public Sub SaveReportTemplateToFile()
    Dim cdb As DAO.Database, rowRst As DAO.Recordset, attachRst As DAO.Recordset2, attachField As DAO.Field2
    Set cdb = CurrentDb
    Set rowRst = cdb.OpenRecordset("SELECT TemplateFile FROM ReportTemplates WHERE ID=1")
    Set attachRst = rowRst.Fields("TemplateFile").Value
    Set attachField = attachRst.Fields("FileData")
    attachField.SaveToFile "C:\Users\Gord\Desktop\" & attachRst.Fields("FileName").Value
    Set attachField = Nothing
    attachRst.Close
    Set attachRst = Nothing
    rowRst.Close
    Set rowRst = Nothing
    Set cdb = Nothing
End Sub

这篇关于在我访问数据库中存储的Excel模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆