Bob*_*ley 7 coldfusion cfwheels coldfusion-10 cfspreadsheet
这更像是一个操作方法,而不是一个实际的问题.(我搜索过,找不到解决办法,所以我想出了这个)
我需要创建一个excel文件导出,允许用户:
我搜索并没有找到解决方案,所以我想出了这个:
使用示例表“薪水”
CREATE TABLE [dbo].[Salary](
[id] [int] IDENTITY(1,1) NOT NULL,
[employee_id] [varchar](36) NULL,
[salary] [decimal](18, 0) NULL,
[createdat] [datetime] NULL,
[updatedat] [datetime] NULL,
[updated_by] [varchar](36) NULL,
[created_by] [varchar](36) NULL )
Run Code Online (Sandbox Code Playgroud)
首先创建一个用于提取 Excel 数据的特殊模型。示例“导出.cfc”
模型\导出.cfc
<cfcomponent extends="Model" output="false">
<cffunction name="init">
<cfset table("Salary")/>
<!--- defined properties to allow spaces in column names via [] alias.--->
<cfset property(sql="employee_id", name="[Employee ID]")>
<cfset property(sql="dbo.getName(employee_id)", name="[The Employee Name]")>
<cfset property(sql="salary", name="[He gets paid what?]")>
<cfset property(sql="CONVERT(VARCHAR, createdAt, 101)", name="[Date Created]")>
</cffunction>
</cfcomponent>
Run Code Online (Sandbox Code Playgroud)
然后只需拉出 Excel 导出所需的特定列即可。([] 是必要的)
<cfset columns = "id,[employee id],[The Employee Name],[He gets paid what?],[Date Created]"/>
<cfset excelData = model("export").findAll(
select=columns,
parameterize=false
) />
<cfspreadsheet
action = "write"
filename="#expandpath('files')#\export.xls"
query="excelData"
overwrite="true">
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
138 次 |
| 最近记录: |