[算表] google sheet 西曆轉農曆

看板Office作者 (被罰跪主機板的)時間4周前 (2025/03/04 15:35), 編輯推噓0(001)
留言1則, 1人參與, 4周前最新討論串1/1
軟體:Google Sheet 求教大神!! 使用Google Sheet 西曆轉農曆,以下是ChatGPT給的回答 台灣中央氣象署提供官方的農曆 API,你可以用它來獲取農曆日期。 function SolarToLunar(date) { var year = date.getFullYear(); var month = ('0' + (date.getMonth() + 1)).slice(-2); // 確保是兩位數 var day = ('0' + date.getDate()).slice(-2); // 確保是兩位數 var url = "https://www.cwa.gov.tw/Data/js/Calendar/Calendar_" + year + ".json"; try { var response = UrlFetchApp.fetch(url); var data = JSON.parse(response.getContentText()); for (var i = 0; i < data.length; i++) { if (data[i].西元年 == year && data[i].月 == month && data[i].日 == day) { return "農曆 " + data[i].農曆年 + " 年 " + data[i].農曆月 + " 月 " + data[i].農曆日 + " 日"; } } return "找不到農曆日期"; } catch (e) { return "API 請求失敗:" + e.message; } } 【執行結果如下】 "API 請求失敗:Request failed for https://www.cwa.gov.tw returned code 404. Truncated server response: <!DOCTYPE html> <!--[if IE 8]> <html lang=""zh-Hant-TW"" class=""ie8""> <![endif]--> <!--[if IE 9]> <html lang=""zh-Hant-TW"" class=""ie9""> <![endif]--> <... (use muteHttpExceptions option to examine full response)" 404好像是網址不對,請問大神,該怎麼修改呢? -- ┌──────────┐┌──────────┐┌─────────────┐ │ ││ ││ │ │ <○ ││ ││ │ │ ■︶ /■> ││ /■\ ╰■\ ││ <囧> /█╯ │ │ || /| ││ || /| ││ ∕) │ └──────────┘└──────────┘└─────────────┘ -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 125.229.232.83 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Office/M.1741073746.A.A1B.html

03/04 18:49, 4周前 , 1F
你有確定那個網址是存在的嗎? ChatGPT有可能會騙你喔
03/04 18:49, 1F
文章代碼(AID): #1dngrIeR (Office)
文章代碼(AID): #1dngrIeR (Office)