跳转到主要内容

将dexterity内容导出到Excel文件,每列一个字段

项目描述

https://secure.travis-ci.org/collective/collective.excelexport.png https://coveralls.io/repos/collective/collective.excelexport/badge.png?branch=master

collective.excelexport

本产品的作用

本产品为 Plone 用户提供在 xls 或 csv 格式下进行 Excel 导出的工具。

一个框架,具有默认的实用工具,可以导出文件夹的 dexterity 内容,目录搜索的结果,以及 eea 分面导航搜索的结果。许多字段类型被管理(文本、列表、文件、布尔值、数据网格…)。

尝试在任何包含 dexterity 元素的文件夹上使用 @@collective.excelexport 观看。尝试在网站根目录上使用 @@collective.excelexport?excelexport.policy=excelexport.search&review_state=published。

尝试在任何文件夹上使用 @@collective.excelexportcsv 观看以进行 csv 导出。

如何配置此产品

您可以通过注册记录设置要排除的字段列表:collective.excelexport.excluded_exportables

如何扩展它

数据源

如果您想实现一种新的内容导出方式,您可以注册一个 #数据源#,它是对 collective.excelexport.interfaces.IDataSource 接口的适配器。

此适配器可以是命名的。

您将调用此数据源,方法是调用视图 @@collective.excelexport?excelexport.policy=数据源名称

有关更多信息,请参阅 IDataSource 接口

可导出内容(Excel 表格列)

如果您想为您的 Excel 导出定义新的列,您将编写或覆盖

- Exportable factories, adapters for IExportableFactory interface that provides a list of Exportables
- Exportables, that define columns.

导出工厂示例

from plone.dexterity.interfaces import IDexterityFTI
from collective.excelexport.exportables.base import BaseExportableFactory
from collective.excelexport.exportables.dexterityfields import get_ordered_fields
from collective.excelexport.exportables.dexterityfields import get_exportable
from collective.excelexport.exportables.dexterityfields import ParentField
from collective.excelexport.exportables.dexterityfields import GrandParentField

class PSTActionFieldsFactory(BaseExportableFactory):
    adapts(IDexterityFTI, Interface, Interface)
    portal_types = ('pstaction',)

    def get_exportables(self):
        portal_types = api.portal.get_tool('portal_types')
        action_fti = portal_types['pstaction']
        oo_fti = portal_types['operationalobjective']
        os_fti = portal_types['strategicobjective']
        fields = []
        fields.extend([get_exportable(
            field[1], self.context, self.request)
            for field in get_ordered_fields(action_fti)])
        fields.extend([get_exportable(
            ParentField(field[1]), self.context, self.request)
            for field in get_ordered_fields(oo_fti)])
        fields.extend([get_exportable(
            GrandParentField(field[1]), self.context, self.request)
            for field in get_ordered_fields(os_fti)])
        return fields

Dexterity 可导出内容

您有一套完整的 dexterity 字段导出内容。这些是多适配器,针对字段、上下文和请求。

您可以通过声明更具体的适配器来覆盖它们。

如果您想为一个特定字段提供特定的渲染,您也可以声明一个带有字段名称的命名适配器。

样式

如果您不喜欢默认样式,您可以为以下内容注册特定的样式:
  • 导出策略

  • 上下文

您只需在 zcml 中注册一个新的 IStyle 适配器即可

<adapter for="zope.interface.Interface
              .interfaces.IThemeSpecific"
         factory=".excelstyles.MyNeutralStyle"
         provides="collective.excelexport.interfaces.IStyles"
          />

如果您没有指定名称,则样式将为所有策略注册

并在 Python 中

class MyNeutralStyle(Styles):

    content = xlwt.easyxf('font: height 200, name Arial, colour_index black, bold off; '
                     'align: wrap off, vert centre, horiz left;'
                     'borders: top thin, bottom thin, left thin, right thin;'
                     'pattern: pattern solid, back_colour white, fore_colour white'
                     )

    headers = xlwt.easyxf('font: height 200, name Arial, colour_index black, bold on; '
                         'align: wrap off, vert centre, horiz left; '
                         'borders: top thin, bottom thin, left thin, right thin; '
                         'pattern: pattern solid, back_colour white, fore_colour white; '
                         )

plone.restapi

要通过 rest api 获取导出,请查询 @collective.excelexport / @collective.excelexportcsv(带有一个 @)

贡献者

变更日志

1.8.2 (2020-02-27)

  • 添加 Python 3 兼容性。 [bsuttor]

1.8.1 (2019-11-06)

  • 安全解码 voc_value(修复编码问题)+ 测试 [boulch]

1.8 (2019-09-12)

# 破坏性变更

CONFIGURATION_FIELDS 常量已删除,我们现在使用注册记录:collective.excelexport.excluded_exportables

# 变更

  • 显式包含 plone.restapi zcml [thomasdesvenain]

  • 排除 dexterity 的“允许讨论”和“从导航中排除”字段(以前,仅排除 archetypes 字段)[thomasdesvenain]

  • 修复当引用对象值没有 Title 方法时的错误。[thomasdesvenain]

  • 修复:如果有默认字段集,则不要省略字段。[petchesi-iulian]

  • 修复 eea.faceted 中的错误,当存在小部件运算符时。[thomasdesvenain]

  • 支持 Archetypes,Products.ATExtensions(RecordField、RecordsField、FormattableNamesField)。[thomasdesvenain]

  • 修复编码问题。

1.7 (2018-06-22)

  • 添加 plone.restapi 服务。[thomasdesvenain]

  • 修复 csv 导出 mime 类型。

  • 添加辅助方法 get_exportable_for_fieldname。[gbastien]

1.6 (2018-01-05)

  • 修复:eeafaceted 数据源中结果数量的限制。[cedricmessiant]

1.5 (2017-11-28)

  • 升级 bootstrap。[sgeulette]

  • 修复:以源词汇[sgeulette]渲染选择字段。

1.4 (2017-05-31)

  • 防止在排序时删除具有相似名称的可导出项。[thomasdesvenain]

  • 重构:视图公开了一个从工作表数据创建数据缓冲区的方法。[thomasdesvenain]

  • 已正确发布。[sgeulette]

1.3 (2016-11-28)

  • 修复:检查集合字段的渲染中value_type是否为空。[bsuttor]

  • 修复:如果字段是方法,则尝试获取方法值,并将DateTime结果转换为unicode,这修复了具有IPublication行为的对象的导出。[pcdummy]

  • 修复:确保不要通过获取来检索对象上的属性。[vincentfretin]

  • 特性:render_style现在可以返回一个具有内容和标题属性的风格对象,以便能够按可导出项自定义标题样式。[vincentfretin]

  • 特性:传递给render_value的obj现在是exportable.field.bind(obj).context,这使得从父级或祖父母获取数据更容易。[vincentfretin]

  • 特性:BaseFieldRenderer.render_header方法现在返回翻译的字段标题,而不是消息对象。[vincentfretin]

  • 修复:在创建导出URL时忽略反向参数。[cedricmessiant]

  • 特性:使用exportables_order列表添加排序可导出项功能。适用于字段和非字段可导出项。[cedricmessiant, ebrehault, thomasdevenain]

1.2 (2014-09-10)

  • 特性:添加了CSV格式的导出。[thomasdesvenain]

  • API:默认情况下,使用excluded_exportables列表通过字段名称过滤可导出项。[cedricmessiant]

  • API:我们可以使用字段名称作为适配器名称来为单个字段定义dexterity适配器。[thomasdesvenain]

  • 修复:分面导航导出链接忽略了每页结果标准。[thomasdesvenain]

  • 修复:翻译工作表标题。[thomasdesvenain]

  • 修复:改进文本字段支持。[fngaha, thomasdesvenain]

1.1 (2014-06-19)

  • 重命名搜索策略excelexport.search以避免与‘search’视图冲突。[thomasdesvenain]

1.0 (2014-06-02)

  • 初始发布。[thomasdesvenain]

项目详情


下载文件

下载您平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源分布

collective.excelexport-1.8.2.tar.gz (39.8 kB 查看哈希值)

上传时间

由以下组织支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页面