将attribute数据动态写入到excel上

显示效果:
I在这里插入图片描述

大体思路:

  • excel range name就设置为attribute_数字_类型,在创建template的时候,通过API得到这个event有几个attribute,就创建几列,同时还要根据不同的类型为下方的单元格设置格式
  • pull的时候,根据attribute_数字_类型 的方式得到具体的range,然后把读取到的数据填充到range里

创建attribute列显示在excel上

// Add filtered attributes as columns with unique namesif (attributes[eventType.attributeEventType] && attributes[eventType.attributeEventType].length > 0) {attributes[eventType.attributeEventType].forEach((attribute, index) => {if(!attribute.showInEventDetails) return; // skip attributes that are not shown in event detailsconst attributeRange = headerRange.getOffsetRange(0, offset);attributeRange.values = [[attribute.attributeName]];attributeRange.format.font.bold = false;// Create a unique name by prefixing "attribute_(index+1)_attribute.type"const uniqueName = `attribute_${index + 1}_${attribute.type}`;sh.names.add(uniqueName, attributeRange);// Get the range for the values below the headerconst valueRange = attributeRange.getOffsetRange(1, 0);// Set format and data validation based on attribute typeswitch (attribute.type) {case 'Bool':// Set data validation for boolean valuesvalueRange.dataValidation.rule = {list: {inCellDropDown: true,source: "True,False",}};break;case 'Date':// Set date formatvalueRange.numberFormat = [['m/d/yyyy h:mm']];break;case "String":valueRange.numberFormat = [['@']];break;default:// Default case if no specific type handling is neededbreak;}offset++;});}

把对应的数据显示在列的下面

for (let index = 0; index < attributes[eventSchema.attributeEventType].length; index++) {const attribute = attributes[eventSchema.attributeEventType][index];if (!attribute.showInEventDetails) continue; // skip attributes that are not shown in event details// Load the range for this attributelet attributeRange = sh.getRange(`attribute_${index + 1}_${attribute.type}`);try {await context.sync()} catch {console.log(`attribute ${attribute.attributeName} can't be found in spreadsheet ${sheetName}`);continue;}// Find the value for this attribute in the event itemlet attributeValue;const attr = ev.attributes?.items?.find(attr => attr.name === attribute.attributeName);if (attr) {switch (attr.type) {case "Boolean":attributeValue = attr.boolValue ? "TRUE" : "FALSE";break;case "String":attributeValue = attr.stringValue;break;case "List":attributeValue = attr.listValue;break;case "Date":attributeValue = this.timeZoneService.convertIsoToExcelDate(attr.dateValue);break;case "Int":attributeValue = attr.intValue;break;case "Float":attributeValue = attr.floatValue;break;default:attributeValue = ""; // Default value if no type matchesbreak;}}// Get the cell range for this attributeconst range = attributeRange.getOffsetRange(i + 1, 0);range.values = [[attributeValue || ""]]; // Set the cell value to the attribute value}

转换ISO时间到excelDate的方法:

public convertIsoToExcelDate(isoString: string): number {if (!isoString) return null;const date = moment.tz(isoString, this.displayTimezone).toDate();const excelDateOffset = 25569;const excelDate = (date.getTime() / (24 * 60 * 60 * 1000)) + (moment(date).utcOffset() / (24 * 60)) + excelDateOffset;return excelDate;}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.pswp.cn/diannao/89122.shtml
繁体地址,请注明出处:http://hk.pswp.cn/diannao/89122.shtml
英文地址,请注明出处:http://en.pswp.cn/diannao/89122.shtml

如若内容造成侵权/违法违规/事实不符,请联系英文站点网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Stable Diffusion入门-ControlNet 深入理解 第一课:ControlNet,控制AI绘图的“大杀器”

大家好&#xff0c;欢迎来到Stable Diffusion入门-ControlNet深入理解系列的第一课&#xff01; 今天&#xff0c;我们要聊聊一个让AI绘画从“盲目生成”走向“精准控制”的神奇插件——ControlNet。 它就像一位无声的魔术师&#xff0c;把原本随意的AI生成图片变得有条不紊、…

新生代潜力股刘小北:演艺路上的璀璨新星

在娱乐圈新人辈出的当下&#xff0c;一位来自四川的年轻演员正凭借着自己独特的魅力和扎实的演技&#xff0c;悄然走进观众的视野&#xff0c;他就是刘小北。1998年出生的刘小北&#xff0c;毕业于四川电影电视学院&#xff0c;自踏入演艺圈以来&#xff0c;便以坚定的步伐在演…

强制IDEA始终使用Java 8

解决IDEA总是使用Java 21而非Java 8编译的问题 您遇到的问题是典型的IDE内置JDK与项目冲突的情况。即使系统只安装了Java 8&#xff0c;IntelliJ IDEA仍内置有最新的Java运行时&#xff0c;导致它使用Java 21来编译您的代码。 解决方案&#xff1a;强制IDEA始终使用Java 8 1…

青少年编程与数学 01-012 通用应用软件简介 14 词典及翻译资源

青少年编程与数学 01-012 通用应用软件简介 14 词典及翻译资源 一、什么是词典及翻译资源&#xff08;一&#xff09;词典及翻译资源的基本定义&#xff08;二&#xff09;词典及翻译资源的工作原理&#xff08;三&#xff09;词典及翻译资源的类型 二、词典及翻译资源的重要意…

AI测试革命:5分钟自动生成单元测试|覆盖率和边界测试实战指南

AI测试革命&#xff1a;5分钟自动生成单元测试&#xff5c;覆盖率和边界测试实战指南 你是否曾为编写测试用例绞尽脑汁&#xff1f;是否因遗漏边界条件导致上线后BUG频发&#xff1f;告别低效测试&#xff0c;掌握AI赋能的现代化测试策略&#xff01; 一、为什么我们需要AI测试…

n8n Docker Compose部署

n8n Docker Compose 部署官方文档详细总结 1. 前提条件 具备服务器、容器、网络和安全相关基础知识。推荐有 Linux 运维经验。已准备好一台服务器&#xff08;建议为云服务器或本地服务器&#xff09;。 2. 安装 Docker 和 Docker Compose 以 Ubuntu 为例&#xff0c;完整命…

Talk is cheap. Show me the code.手搓一个 Wayland 客户端程序

前几天我写了一篇万字长文《万字长文详解 Wayland 协议、架构》&#xff0c;但光讲协议分析难免有些枯燥。毕竟&#xff0c;程序员更信奉那句名言&#xff1a;Talk is cheap. Show me the code. 所以这篇文章不打算长篇大论&#xff0c;而是通过编写一个简单的 Wayland 客户端程…

Golang JSON 标准库用法详解

JSON (JavaScript Object Notation) 是一种轻量级的数据交换格式&#xff0c;Go语言的标准库encoding/json提供了强大的JSON处理能力。下面我将详细介绍各种用法并提供示例代码。 1. 基本编码&#xff08;Marshal&#xff09; 将Go数据结构转换为JSON字符串。 package maini…

Day.42

hook函数&#xff1a; import torch import torch.nn as nn import numpy as np import matplotlib.pyplot as plt torch.manual_seed(42) np.random.seed(42) 张量钩子&#xff1a; x torch.tensor([2.0], requires_gradTrue) y x ** 2 z y ** 3 def tensor_hook…

【.net core】【sqlsugar】在where条件查询时使用原生SQL

//初始化查询 var query repository.IQueryable();//添加原生SQL WHERE条件 query query.Where(" fieldA < 123"); 对应调用ISugarQueryable接口类中&#xff1a; ISugarQueryable<T> Where(string whereString, object parameters null);

网络 : 传输层【TCP协议】

网络 : 传输层【TCP协议】 一、TCP协议段格式1.1 32位序号与确认号1.1.1 32位序号1.1.2 确认号 1.2 4位首部长度1.3 6位标志位1.4 16位窗口大小 二、确认应答(ACK)机制三、超时重传机制四、连接管理机制4.1 三次握手(连接)listen的第二个参数 4.2 四次挥手(断开连接)**TIME_WAI…

人大金仓Kingbase数据库 Ksql: 未找到命令

人大金仓Kingbase数据库 Ksql: 未找到命令 1. 定位 Kingbase 安装目录 Kingbase 数据库通常安装在 /kingbase/ES/V8/Server 目录下。可以通过以下命令定位&#xff1a; cd /kingbase/ES/V8/Server2. 验证 ksql 工具是否安装成功 执行以下命令检查 ksql 客户端工具的版本信息…

Flask(四) 模板渲染render_template

文章目录 &#x1f4e6; 过程详解&#xff08;路由 <-> HTML 模板&#xff09;&#x1f9e0; 数据是怎么传过去的&#xff1f;多变量示例 ✅ Jinja2 支持条件判断、循环、模板继承&#xff1a;✅ 安全性&#x1f512; Flask 默认也会对变量进行 HTML 转义&#xff1a;&am…

[附源码+数据库+毕业论文+开题报告]基于Spring+MyBatis+MySQL+Maven+jsp实现的宠物领养管理系统,推荐!

摘 要 互联网发展至今&#xff0c;无论是其理论还是技术都已经成熟&#xff0c;而且它广泛参与在社会中的方方面面。它让信息都可以通过网络传播&#xff0c;搭配信息管理工具可以很好地为人们提供服务。针对宠物领养信息管理混乱&#xff0c;出错率高&#xff0c;信息安全性差…

【ArcGIS】水资源单项评价

【ArcGIS】水资源单项评价 一、水资源单项评价1、评价思路 二、操作步骤1、处理环境设置2、数据处理3、要素转栅格4、水资源评价 一、水资源单项评价 1、评价思路 &#xff08;1&#xff09;省级层面宜选用四级/五级水资源分区或县级行政区为评价单元&#xff0c;按照水资源总…

Windows环境下C语言汇编语言编辑器及环境安装

安装MinGw&#xff1a; 1.下载安装文件 MinGW - 适用于 Windows 的极简主义 GNU 下载 |SourceForge.net 点击下载 下载之后就是如下图的安装文件 2.安装 双击安装文件进行安装&#xff0c;点击Install下一步 选择安装位置&#xff0c;默认是安装在C盘&#xff0c;点击Change…

【数据分析】分段逻辑回归示例分析(模拟数据)

禁止商业或二改转载,仅供自学使用,侵权必究,如需截取部分内容请后台联系作者! 文章目录 介绍加载R包步骤 1:模拟数据步骤 2:构建逻辑回归和分段模型步骤 3:计算预测值和置信区间步骤 4:提取 OR 和统计值步骤 5:绘图展示结步骤 6:输出图片原始代码总结系统信息参考介绍…

Webpack 构建过程详解

Webpack 是一个功能强大的模块打包工具,它能够将项目中的各种资源(如 JavaScript、CSS、图片等)打包成一个或多个文件,以便于在浏览器中运行。本文将以 Webpack 5 为例介绍它的构建过程: 1. 初始化阶段 在这个阶段,Webpack 从配置文件和命令行参数中读取并解析配置。然…

Flutter基础(UI监听)

文本按钮&#xff08;TextButton&#xff09; 文本按钮是没有边框的按钮&#xff0c;当点击时会有涟漪效果。 TextButton(onPressed: () {// 点击按钮后要执行的代码print(文本按钮被点击了);},child: Text(点击我), ) 手势检测器&#xff08;GestureDetector&#xff09; …

Linux 下的 regulator 子系统

1、简介 regulator 框架是 Linux 内核中用于管理电压和电流调节器&#xff08;如 LDO、DCDC 转换器等&#xff09;的一个子系统。它提供了一个抽象层&#xff0c;使得驱动程序和内核的其他部分可以以一致的方式与调节器进行交互&#xff0c;而无需了解底层硬件的细节。 主要功能…