Tag: 多表

从多个数据库表以编程方式创build数据透视表

我有一个自动化Excel的问题,我无法解决。 我想模仿“导入外部数据”function。 它已经完美地适用于平面表,但不适用于数据透视表,当我为导入select多个数据库表时。 手动的方式 我有一个Access数据库与2个表(帐户和交易),由外键(交易表中的“帐户”)链接。 我想要立即导入到数据透视表。 通常的方法是点击“数据” – >“外部数据”,然后在对话框中select两个表格,然后select“数据透视表”并点击“确定”。 现在数据透视表位于活动工作表中,右侧是提供导入表的层次结构中所有字段的字段列表。 这是我想模仿提到的数据库文件。 有没有人有一个想法这是如何工作的? 我试过了 我已经试图logging和修改一个macros,但没有成功,因为它logging了不完整和有缺陷的代码。 不完整,因为logging的代码没有创build数据模型,但这显然是必要的(?)。 由于代码无法运行,因此语法错误。 我可以从一个数据库表成功创build数据透视表,如下所示: Excel.PivotCaches pivotCaches = workbook.PivotCaches(); Excel.PivotCache pivotCache = pivotCaches.Create(Excel.XlPivotTableSourceType.xlExternal, Type.Missing, Type.Missing); pivotCache.Connection = conStr; pivotCache.MaintainConnection = true; pivotCache.CommandText = "Accounts"; pivotCache.CommandType = Excel.XlCmdType.xlCmdTable; Excel.PivotTables pivotTables = sheet.PivotTables(); Excel.PivotTable pivotTable = pivotTables.Add(pivotCache, sheet.get_Range("A3", "C20"), "Pivot", Type.Missing, Type.Missing); 但是,我试图获得多个数据库表的每一次尝试都失败了。 什么是去多个表的方式? 请记住,我不一定知道表名称和连接字段,再加上我不想失去表格之间的区别,它应该保留在数据透视表字段列表中,以便对字段进行分层select。 […]

Django – 根据模型字段生成excel报告

该应用程序是build立在Django /angular 。 我想生成一个基于模型的Excel报告,它是用户select的字段。 你可以在下面findsearch界面。 我在django有4个模型。 教练 , 球员 , 参与 俱乐部的外部参照(一对多关系)。 个人Django模型将作为selectinput和模型字段 models.py from datetime import datetime from django.db import models class Club(models.Model): name = models.CharField(max_length=200) estd = models.IntegerField() address = models.CharField(max_length=200) def __unicode__(self): return "%s" % self.name class Coach(models.Model): fname = models.CharField(max_length=80) lname = models.CharField(max_length=80) age = models.IntegerField() fk = models.ForeignKey(Club, related_name='coaches') def […]