將attribute數據動態寫入到excel上

將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;而無需了解底層硬件的細節。 主要功能…