excel公历转农历的四种方法

合集下载

公历转农历EXCEL宏讲解

公历转农历EXCEL宏讲解

Public Function NongLi(Optional XX_DATE As Date)Dim MonthAdd(11), NongliData(99), TianGan(9), DiZhi(11), ShuXiang(11), DayName(30), MonName(12)Dim curTime, curYear, curMonth, curDayDim GongliStr, NongliStr, NongliDayStrDim i, m, n, k, isEnd, bit, TheDate'»ñÈ¡µ±Ç°ÏµÍ³Ê±¼äcurTime = XX_DATE'Ìì¸ÉÃû³ÆTianGan(0) = "¼×"TianGan(1) = "ÒÒ"TianGan(2) = "±û"TianGan(3) = "¶¡"TianGan(4) = "Îì"TianGan(5) = "¼º"TianGan(6) = "¸ý"TianGan(7) = "ÐÁ"TianGan(8) = "ÈÉ"TianGan(9) = "¹ï"'µØÖ§Ãû³ÆDiZhi(0) = "×Ó"DiZhi(1) = "³ó"DiZhi(2) = "Òú"DiZhi(3) = "î"DiZhi(4) = "³½"DiZhi(5) = "ËÈ"DiZhi(6) = "Îç"DiZhi(7) = "δ"DiZhi(8) = "Éê"DiZhi(9) = "ÓÏ"DiZhi(10) = "Ðç"DiZhi(11) = "º¥"'ÊôÏàÃû³ÆShuXiang(0) = "Êó"ShuXiang(1) = "Å£"ShuXiang(2) = "»¢"ShuXiang(3) = "ÍÃ"ShuXiang(4) = "Áú"ShuXiang(5) = "Éß"ShuXiang(6) = "Âí"ShuXiang(7) = "Ñò" ShuXiang(8) = "ºï" ShuXiang(9) = "¼¦" ShuXiang(10) = "¹·" ShuXiang(11) = "Öí" 'Å©ÀúÈÕÆÚÃûDayName(0) = "*" DayName(1) = "³õÒ»" DayName(2) = "³õ¶þ" DayName(3) = "³õÈý" DayName(4) = "³õËÄ" DayName(5) = "³õÎå" DayName(6) = "³õÁù" DayName(7) = "³õÆß" DayName(8) = "³õ°Ë" DayName(9) = "³õ¾Å" DayName(10) = "³õÊ®" DayName(11) = "ʮһ" DayName(12) = "Ê®¶þ" DayName(13) = "Ê®Èý" DayName(14) = "Ê®ËÄ" DayName(15) = "Ê®Îå" DayName(16) = "Ê®Áù" DayName(17) = "Ê®Æß" DayName(18) = "Ê®°Ë" DayName(19) = "Ê®¾Å" DayName(20) = "¶þÊ®" DayName(21) = "Ø¥Ò»" DayName(22) = "Ø¥¶þ" DayName(23) = "Ø¥Èý" DayName(24) = "Ø¥ËÄ" DayName(25) = "Ø¥Îå" DayName(26) = "Ø¥Áù" DayName(27) = "Ø¥Æß" DayName(28) = "Ø¥°Ë" DayName(29) = "Ø¥¾Å" DayName(30) = "ÈýÊ®" 'Å©ÀúÔ·ÝÃûMonName(0) = "*" MonName(1) = "Õý" MonName(2) = "¶þ" MonName(3) = "Èý" MonName(4) = "ËÄ" MonName(5) = "Îå"MonName(6) = "Áù" MonName(7) = "Æß" MonName(8) = "°Ë" MonName(9) = "¾Å" MonName(10) = "Ê®" MonName(11) = "ʮһ" MonName(12) = "À°"'¹«ÀúÿÔÂÇ°ÃæµÄÌìÊý MonthAdd(0) = 0 MonthAdd(1) = 31 MonthAdd(2) = 59 MonthAdd(3) = 90 MonthAdd(4) = 120 MonthAdd(5) = 151 MonthAdd(6) = 181 MonthAdd(7) = 212 MonthAdd(8) = 243 MonthAdd(9) = 273 MonthAdd(10) = 304 MonthAdd(11) = 334'Å©ÀúÊý¾ÝNongliData(0) = 2635 NongliData(1) = 333387 NongliData(2) = 1701 NongliData(3) = 1748 NongliData(4) = 267701 NongliData(5) = 694 NongliData(6) = 2391 NongliData(7) = 133423 NongliData(8) = 1175 NongliData(9) = 396438 NongliData(10) = 3402 NongliData(11) = 3749 NongliData(12) = 331177 NongliData(13) = 1453 NongliData(14) = 694 NongliData(15) = 201326 NongliData(16) = 2350 NongliData(17) = 465197 NongliData(18) = 3221 NongliData(19) = 3402 NongliData(20) = 400202 NongliData(21) = 2901 NongliData(22) = 1386NongliData(24) = 605 NongliData(25) = 2349 NongliData(26) = 137515 NongliData(27) = 2709 NongliData(28) = 464533 NongliData(29) = 1738 NongliData(30) = 2901 NongliData(31) = 330421 NongliData(32) = 1242 NongliData(33) = 2651 NongliData(34) = 199255 NongliData(35) = 1323 NongliData(36) = 529706 NongliData(37) = 3733 NongliData(38) = 1706 NongliData(39) = 398762 NongliData(40) = 2741 NongliData(41) = 1206 NongliData(42) = 267438 NongliData(43) = 2647 NongliData(44) = 1318 NongliData(45) = 204070 NongliData(46) = 3477 NongliData(47) = 461653 NongliData(48) = 1386 NongliData(49) = 2413 NongliData(50) = 330077 NongliData(51) = 1197 NongliData(52) = 2637 NongliData(53) = 268877 NongliData(54) = 3365 NongliData(55) = 531109 NongliData(56) = 2900 NongliData(57) = 2922 NongliData(58) = 398042 NongliData(59) = 2395 NongliData(60) = 1179 NongliData(61) = 267415 NongliData(62) = 2635 NongliData(63) = 661067 NongliData(64) = 1701 NongliData(65) = 1748 NongliData(66) = 398772NongliData(68) = 2391NongliData(69) = 330031NongliData(70) = 1175NongliData(71) = 1611NongliData(72) = 200010NongliData(73) = 3749NongliData(74) = 527717NongliData(75) = 1452NongliData(76) = 2742NongliData(77) = 332397NongliData(78) = 2350NongliData(79) = 3222NongliData(80) = 268949NongliData(81) = 3402NongliData(82) = 3493NongliData(83) = 133973NongliData(84) = 1386NongliData(85) = 464219NongliData(86) = 605NongliData(87) = 2349NongliData(88) = 334123NongliData(89) = 2709NongliData(90) = 2890NongliData(91) = 267946NongliData(92) = 2773NongliData(93) = 592565NongliData(94) = 1210NongliData(95) = 2651NongliData(96) = 395863NongliData(97) = 1323NongliData(98) = 2707NongliData(99) = 265877'Éú³Éµ±Ç°¹«ÀúÄê¡¢Ô¡¢ÈÕ ==> GongliStrcurYear = Year(curTime)curMonth = Month(curTime)curDay = Day(curTime)GongliStr = curYear & "Äê"If (curMonth < 10) ThenGongliStr = GongliStr & "0" & curMonth & "ÔÂ" ElseGongliStr = GongliStr & curMonth & "ÔÂ"End IfIf (curDay < 10) ThenGongliStr = GongliStr & "0" & curDay & "ÈÕ"ElseGongliStr = GongliStr & curDay & "ÈÕ"End If'¼ÆËãµ½³õʼʱ¼ä1921Äê2ÔÂ8ÈÕµÄÌìÊý£º1921-2-8(ÕýÔ³õÒ»)TheDate = (curYear - 1921) * 365 + Int((curYear - 1921) / 4) + curDay + MonthAdd(curMonth - 1) - 38If ((curYear Mod 4) = 0 And curMonth > 2) ThenTheDate = TheDate + 1End If'¼ÆËãÅ©ÀúÌì¸É¡¢µØÖ§¡¢Ô¡¢ÈÕisEnd = 0m = 0DoIf (NongliData(m) < 4095) Thenk = 11Elsek = 12End Ifn = kDoIf (n < 0) ThenExit DoEnd If'»ñÈ¡NongliData(m)µÄµÚn¸ö¶þ½øÖÆλµÄÖµbit = NongliData(m)For i = 1 To n Step 1bit = Int(bit / 2)Nextbit = bit Mod 2If (TheDate <= 29 + bit) ThenisEnd = 1Exit DoEnd IfTheDate = TheDate - 29 - bitn = n - 1LoopIf (isEnd = 1) ThenExit DoEnd Ifm = m + 1LoopcurYear = 1921 + mcurMonth = k - n + 1curDay = TheDateIf (k = 12) ThenIf (curMonth = (Int(NongliData(m) / 65536) + 1)) ThencurMonth = 1 - curMonthElseIf (curMonth > (Int(NongliData(m) / 65536) + 1)) ThencurMonth = curMonth - 1End IfEnd If'Éú³ÉÅ©ÀúÌì¸É¡¢µØÖ§¡¢ÊôÏà ==> NongliStrNongliStr = "Å©Àú" & TianGan(((curYear - 4) Mod 60) Mod 10) & DiZhi(((curYear - 4) Mod 60) Mod 12) & "Äê"NongliStr = NongliStr & "(" & ShuXiang(((curYear - 4) Mod 60) Mod 12) & ")"'Éú³ÉÅ©ÀúÔ¡¢ÈÕ ==> NongliDayStrIf (curMonth < 1) ThenNongliDayStr = "Èò" & MonName(-1 * curMonth)ElseNongliDayStr = MonName(curMonth)End IfNongliDayStr = NongliDayStr & "ÔÂ"NongliDayStr = NongliDayStr & DayName(curDay)NongLi = NongliStr & NongliDayStrEnd Function。

excel公历转农历的四种方法

excel公历转农历的四种方法

excel公历转农历的四种方法excel公历转农历方法一:使用text函数A列是公历日期,我们在B1单元格输入公式:=TEXT(A1,"[$-130000]yyyy年m月"&I F(LEN(--TEXT(A1,"[$-130000]dd"))=1,"初","")&"d"),下拉完成公历转农历。

excel公历转农历方法二:使用text+MID函数A列仍然是公历,B1输入公式:=MID("甲乙丙丁戊己庚辛壬癸",MOD(TEXT(A1,"[$-13 0000]e")-4,10)+1,1)&MID("子丑寅卯辰巳午未申酉戌亥",MOD(TEXT(A1,"[$-130000]e")-4, 12)+1,1)&"年"&TEXT(A1,"[$-130000][DBNum1]m月d日"即可。

excel公历转农历方法三:使用text+MID+ CHOOSE+ YEAR函数A1为公历,B1输入:=CHOOSE(MOD(YEAR(A1)-1900,10)+1,"庚","辛","壬","癸","甲", "乙","丙","丁","戊","己")&CHOOSE(MOD(YEAR(A1)-1900,12)+1,"子","丑","寅","卯","辰","巳","午","未","申","酉","戌","亥")&TEXT(A1,"[dbnum1][$-130000]年m月"&IF(--TEXT(A1, "[$-130000]d")<11,"初","")&TEXT(A1,"[dbnum1][$-130000]d"))excel公历转农历方法四:使用自定义函数上面介绍的excel公历转农历都是使用excel内置函数完成的,有一个弊端就是公式太长,如果使用自定义函数,在公式栏就可以简化输入。

excel制作周历 农历阳历转换

excel制作周历 农历阳历转换

步骤一,在Excel工作表界面下按<ALT+F11>组合键打开VBA窗口,进入VBA编辑环境,在其窗口的菜单栏上依次单击“插入”→“模块”,可在当前VBA工程中插入模块,并直接进入此模块的代码编辑区域。

可在此编辑区域中输入自定义函数的程序代码,如图:Public Function NongLi(Optional XX_DATE As Date)Dim MonthAdd(11), NongliData(99), TianGan(9), DiZhi(11), ShuXiang(11), DayName(30), MonName(12)Dim curTime, curYear, curMonth, curDayDim GongliStr, NongliStr, NongliDayStrDim i, m, n, k, isEnd, bit, TheDate'获取当前系统时间curTime = XX_DATE'天干名称TianGan(0) = "甲"TianGan(1) = "乙"TianGan(2) = "丙"TianGan(3) = "丁"TianGan(4) = "戊"TianGan(5) = "己"TianGan(6) = "庚"TianGan(7) = "辛"TianGan(8) = "壬"TianGan(9) = "癸"'地支名称DiZhi(0) = "子"DiZhi(1) = "丑"DiZhi(2) = "寅"DiZhi(3) = "卯"DiZhi(4) = "辰"DiZhi(5) = "巳"DiZhi(6) = "午"DiZhi(7) = "未"DiZhi(8) = "申"DiZhi(9) = "酉"DiZhi(10) = "戌"DiZhi(11) = "亥"'属相名称ShuXiang(0) = "鼠" ShuXiang(1) = "牛" ShuXiang(2) = "虎" ShuXiang(3) = "兔" ShuXiang(4) = "龙" ShuXiang(5) = "蛇" ShuXiang(6) = "马" ShuXiang(7) = "羊" ShuXiang(8) = "猴" ShuXiang(9) = "鸡" ShuXiang(10) = "狗" ShuXiang(11) = "猪" '农历日期名DayName(0) = "*" DayName(1) = "初一" DayName(2) = "初二" DayName(3) = "初三" DayName(4) = "初四" DayName(5) = "初五" DayName(6) = "初六" DayName(7) = "初七" DayName(8) = "初八" DayName(9) = "初九" DayName(10) = "初十" DayName(11) = "十一" DayName(12) = "十二" DayName(13) = "十三" DayName(14) = "十四" DayName(15) = "十五" DayName(16) = "十六"DayName(17) = "十七" DayName(18) = "十八" DayName(19) = "十九" DayName(20) = "二十" DayName(21) = "廿一" DayName(22) = "廿二" DayName(23) = "廿三" DayName(24) = "廿四" DayName(25) = "廿五" DayName(26) = "廿六" DayName(27) = "廿七" DayName(28) = "廿八" DayName(29) = "廿九" DayName(30) = "三十" '农历月份名MonName(0) = "*" MonName(1) = "正" MonName(2) = "二" MonName(3) = "三" MonName(4) = "四" MonName(5) = "五" MonName(6) = "六" MonName(7) = "七" MonName(8) = "八" MonName(9) = "九" MonName(10) = "十" MonName(11) = "十一" MonName(12) = "腊"'公历每月前面的天数MonthAdd(0) = 0 MonthAdd(1) = 31 MonthAdd(2) = 59 MonthAdd(3) = 90 MonthAdd(4) = 120 MonthAdd(5) = 151 MonthAdd(6) = 181 MonthAdd(7) = 212 MonthAdd(8) = 243 MonthAdd(9) = 273 MonthAdd(10) = 304 MonthAdd(11) = 334'农历数据NongliData(0) = 2635 NongliData(1) = 333387NongliData(3) = 1748 NongliData(4) = 267701 NongliData(5) = 694 NongliData(6) = 2391 NongliData(7) = 133423 NongliData(8) = 1175 NongliData(9) = 396438 NongliData(10) = 3402 NongliData(11) = 3749 NongliData(12) = 331177 NongliData(13) = 1453 NongliData(14) = 694 NongliData(15) = 201326 NongliData(16) = 2350 NongliData(17) = 465197 NongliData(18) = 3221 NongliData(19) = 3402 NongliData(20) = 400202 NongliData(21) = 2901 NongliData(22) = 1386 NongliData(23) = 267611 NongliData(24) = 605 NongliData(25) = 2349 NongliData(26) = 137515 NongliData(27) = 2709 NongliData(28) = 464533 NongliData(29) = 1738 NongliData(30) = 2901 NongliData(31) = 330421 NongliData(32) = 1242 NongliData(33) = 2651 NongliData(34) = 199255 NongliData(35) = 1323 NongliData(36) = 529706 NongliData(37) = 3733 NongliData(38) = 1706 NongliData(39) = 398762 NongliData(40) = 2741 NongliData(41) = 1206 NongliData(42) = 267438 NongliData(43) = 2647 NongliData(44) = 1318 NongliData(45) = 204070NongliData(47) = 461653 NongliData(48) = 1386 NongliData(49) = 2413 NongliData(50) = 330077 NongliData(51) = 1197 NongliData(52) = 2637 NongliData(53) = 268877 NongliData(54) = 3365 NongliData(55) = 531109 NongliData(56) = 2900 NongliData(57) = 2922 NongliData(58) = 398042 NongliData(59) = 2395 NongliData(60) = 1179 NongliData(61) = 267415 NongliData(62) = 2635 NongliData(63) = 661067 NongliData(64) = 1701 NongliData(65) = 1748 NongliData(66) = 398772 NongliData(67) = 2742 NongliData(68) = 2391 NongliData(69) = 330031 NongliData(70) = 1175 NongliData(71) = 1611 NongliData(72) = 200010 NongliData(73) = 3749 NongliData(74) = 527717 NongliData(75) = 1452 NongliData(76) = 2742 NongliData(77) = 332397 NongliData(78) = 2350 NongliData(79) = 3222 NongliData(80) = 268949 NongliData(81) = 3402 NongliData(82) = 3493 NongliData(83) = 133973 NongliData(84) = 1386 NongliData(85) = 464219 NongliData(86) = 605 NongliData(87) = 2349 NongliData(88) = 334123 NongliData(89) = 2709NongliData(91) = 267946NongliData(92) = 2773NongliData(93) = 592565NongliData(94) = 1210NongliData(95) = 2651NongliData(96) = 395863NongliData(97) = 1323NongliData(98) = 2707NongliData(99) = 265877'生成当前公历年、月、日==> GongliStrcurYear = Year(curTime)curMonth = Month(curTime)curDay = Day(curTime)GongliStr = curYear & "年"If (curMonth < 10) ThenGongliStr = GongliStr & "0" & curMonth & "月"ElseGongliStr = GongliStr & curMonth & "月"End IfIf (curDay < 10) ThenGongliStr = GongliStr & "0" & curDay & "日"ElseGongliStr = GongliStr & curDay & "日"End If'计算到初始时间1921年2月8日的天数:1921-2-8(正月初一)TheDate = (curYear - 1921) * 365 + Int((curYear - 1921) / 4) + curDay + MonthAdd(curMonth - 1) - 38If ((curYear Mod 4) = 0 And curMonth > 2) ThenTheDate = TheDate + 1End If'计算农历天干、地支、月、日isEnd = 0m = 0DoIf (NongliData(m) < 4095) Thenk = 11Elsek = 12End Ifn = kDoIf (n < 0) ThenExit DoEnd If'获取NongliData(m)的第n个二进制位的值bit = NongliData(m)For i = 1 To n Step 1bit = Int(bit / 2)Nextbit = bit Mod 2If (TheDate <= 29 + bit) ThenisEnd = 1Exit DoEnd IfTheDate = TheDate - 29 - bitn = n - 1LoopIf (isEnd = 1) ThenExit DoEnd Ifm = m + 1LoopcurYear = 1921 + mcurMonth = k - n + 1curDay = TheDateIf (k = 12) ThenIf (curMonth = (Int(NongliData(m) / 65536) + 1)) ThencurMonth = 1 - curMonthElseIf (curMonth > (Int(NongliData(m) / 65536) + 1)) ThencurMonth = curMonth - 1End IfEnd If'生成农历天干、地支、属相==> NongliStrNongliStr = "农历" & TianGan(((curYear - 4) Mod 60) Mod 10) & DiZhi(((curYear - 4) Mod 60) Mod 12) & "年"NongliStr = NongliStr & "(" & ShuXiang(((curYear - 4) Mod 60) Mod 12) & ")"'生成农历月、日==> NongliDayStrIf (curMonth < 1) ThenNongliDayStr = "闰" & MonName(-1 * curMonth)ElseNongliDayStr = MonName(curMonth)End IfNongliDayStr = NongliDayStr & "月"NongliDayStr = NongliDayStr & DayName(curDay)NongLi = NongliStr & NongliDayStrEnd Function步骤2,单击窗口右上角的“关闭”按钮关闭VBA编辑窗口,返回到工作表窗口中。

Excel实现公历农历转换的三种方法

Excel实现公历农历转换的三种方法

Excel实现公历农历转换的三种⽅法【导读】:有时候我们在输⼊⽇期数据的时候,往往需要输⼊农历的⽇期,但已经输⼊的⽇期是公历的⽇期,那么该怎么转换呢?接下来我们将为⼤家如何利⽤excel函数进⾏将公历⽇期转化为农历⽇期!⼀、简单版下表中B2单元格就是第⼀种情况,“2016-9-17”表⽰农历是九⽉⼗七⽇。

该公式是:=TEXT(A2,"[$-130000]YYYY-M-D")。

TEXT()⽤来转化⽂本格式,这个公式的关键是:[$-130000],它是Excel中阳历转化农历的参数,不过它存在⼀个问题就是没法计算闰⽉,估计⽼外⽆法理解中国⼈闰⽉的概念,凡是闰年,它直接表⽰⼀年13个⽉,道理是⼀样的。

⼆、进阶版(中⽂呈现)上表C2单元格,相⽐较B2单元格呈现就有了进阶,以中⽂呈现,并且以天⼲地⽀表现年份。

公式相对之前肯定复杂:=MID(" 甲⼄丙丁戊⼰庚⾟壬癸",MOD(TEXT(A2,"[$-130000]e")-4,10)+1,1)&MID("⼦丑寅卯⾠巳午未申⾣戌亥",MOD(TEXT(A2,"[$-130000]e")-4,12)+1,1)&"年"&TEXT(A2," [$-130000] [DBNum1]m⽉d⽇")我们可以分解为两⼤部分:1)计算年份:MID(" 甲⼄丙丁戊⼰庚⾟壬癸",MOD(TEXT(A2,"[$-130000]e")-4,10)+1,1)&MID("⼦丑寅卯⾠巳午未申⾣戌亥",MOD(TEXT(A2,"[$-130000]e")-4,12)+1,1)&"年",这⾥加了MID()⽂本提取函数来获取天⼲地⽀。

EXCEL VBA 实例:将日期转换成农历

EXCEL VBA 实例:将日期转换成农历

Ehi(9) = "酉" DiZhi(10) = "戌" DiZhi(11) = "亥" '属相名称 ShuXiang(0) = "鼠" ShuXiang(1) = "牛" ShuXiang(2) = "虎" ShuXiang(3) = "兔" ShuXiang(4) = "龙" ShuXiang(5) = "蛇" ShuXiang(6) = "马" ShuXiang(7) = "羊" ShuXiang(8) = "猴" ShuXiang(9) = "鸡" ShuXiang(10) = "狗" ShuXiang(11) = "猪" '农历日期名 DayName(0) = "*" DayName(1) = "初一" DayName(2) = "初二" DayName(3) = "初三" DayName(4) = "初四" DayName(5) = "初五" DayName(6) = "初六" DayName(7) = "初七" DayName(8) = "初八" DayName(9) = "初九" DayName(10) = "初十" DayName(11) = "十一" DayName(12) = "十二" DayName(13) = "十三" DayName(14) = "十四" DayName(15) = "十五" DayName(16) = "十六" DayName(17) = "十七" DayName(18) = "十八" DayName(19) = "十九" DayName(20) = "二十" DayName(21) = "二十一" DayName(22) = "二十二" DayName(23) = "二十三" DayName(24) = "二十四" DayName(25) = "二十五" DayName(26) = "二十六" DayName(27) = "二十七" DayName(28) = "二十八" — 第 2 页 共 7 页 —

在Excel中自定义公历转换农历函数2

在Excel中自定义公历转换农历函数2
求阳历2006-11-1日对应的阴历 求阴历2006年正月初一对应的阳历 阳历1975年5月6日出生,今年阴历生日时对应的阳历日期
#NAME? #NAME? #NAME?
阳历生日:阳历1975年5月6日出生,今年阳历生日时对应的阳历日期
#NAME?
End Type
Do
Loop
Loop
&HB4A43, &H4B5537 , &HAD54A, &H955ABF , &H4BA53, &HA5B48, &H652BBC , &H52B50, &HA9345, &H474AB9 ,_
&H6AA4C, &HAD541, &H24DAB6 , &H4B64A, &H69573D , &HA4E51, &HD2646, &H5E933A , &HD534D, &H5AA43, _
LunarDat a.leapmo nth = Int(ng / d)
ng = ng Mod d
d= &H80
mdata = Int(ng / d)
ng = ng Mod d
d= &H20
LunarDat a.sp_mon th = Int(ng / d)
LunarDat a.sp_day = ng Mod d
y= a.Month( 13)
Else
l_month = l_month +1
y= a.Month( l_month)
End If Loop
l_day = l_day + 1
lunar = l_year & "-" & l_month & "-" & l_day

在excel中实现阳历转化阴历

在excel中实现阳历转化阴历

步骤一,在Excel工作表界面下按<ALT+F11>组合键打开VBA窗口,进入VBA编辑环境,在其窗口的菜单栏上依次单击“插入”→“模块”,可在当前VBA工程中插入模块,并直接进入此模块的代码编辑区域。

可在此编辑区域中输入自定义函数的程序代码,如图:Public Function NongLi(Optional XX_DATE As Date)Dim MonthAdd(11), NongliData(99), TianGan(9), DiZhi(11), ShuXiang(11), DayName(30), MonName(12)Dim curTime, curYear, curMonth, curDayDim GongliStr, NongliStr, NongliDayStrDim i, m, n, k, isEnd, bit, TheDate'获取当前系统时间curTime = XX_DATE'天干名称TianGan(0) = "甲"TianGan(1) = "乙"TianGan(2) = "丙"TianGan(3) = "丁"TianGan(4) = "戊"TianGan(5) = "己"TianGan(6) = "庚"TianGan(7) = "辛"TianGan(8) = "壬"TianGan(9) = "癸"'地支名称DiZhi(0) = "子"DiZhi(1) = "丑"DiZhi(2) = "寅"DiZhi(3) = "卯"DiZhi(4) = "辰"DiZhi(5) = "巳"DiZhi(6) = "午"DiZhi(7) = "未"DiZhi(8) = "申"DiZhi(9) = "酉"DiZhi(10) = "戌"DiZhi(11) = "亥"'属相名称ShuXiang(0) = "鼠" ShuXiang(1) = "牛" ShuXiang(2) = "虎" ShuXiang(3) = "兔" ShuXiang(4) = "龙" ShuXiang(5) = "蛇" ShuXiang(6) = "马" ShuXiang(7) = "羊" ShuXiang(8) = "猴" ShuXiang(9) = "鸡" ShuXiang(10) = "狗" ShuXiang(11) = "猪" '农历日期名DayName(0) = "*" DayName(1) = "初一" DayName(2) = "初二" DayName(3) = "初三" DayName(4) = "初四" DayName(5) = "初五" DayName(6) = "初六" DayName(7) = "初七" DayName(8) = "初八" DayName(9) = "初九" DayName(10) = "初十" DayName(11) = "十一" DayName(12) = "十二" DayName(13) = "十三" DayName(14) = "十四" DayName(15) = "十五" DayName(16) = "十六" DayName(17) = "十七" DayName(18) = "十八" DayName(19) = "十九" DayName(20) = "二十" DayName(21) = "廿一" DayName(22) = "廿二" DayName(23) = "廿三" DayName(24) = "廿四" DayName(25) = "廿五" DayName(26) = "廿六" DayName(27) = "廿七" DayName(28) = "廿八" DayName(29) = "廿九" DayName(30) = "三十"'农历月份名MonName(0) = "*" MonName(1) = "正" MonName(2) = "二" MonName(3) = "三" MonName(4) = "四" MonName(5) = "五" MonName(6) = "六" MonName(7) = "七" MonName(8) = "八" MonName(9) = "九" MonName(10) = "十" MonName(11) = "十一" MonName(12) = "腊"'公历每月前面的天数MonthAdd(0) = 0 MonthAdd(1) = 31 MonthAdd(2) = 59 MonthAdd(3) = 90 MonthAdd(4) = 120 MonthAdd(5) = 151 MonthAdd(6) = 181 MonthAdd(7) = 212 MonthAdd(8) = 243 MonthAdd(9) = 273 MonthAdd(10) = 304 MonthAdd(11) = 334'农历数据NongliData(0) = 2635 NongliData(1) = 333387 NongliData(2) = 1701 NongliData(3) = 1748 NongliData(4) = 267701 NongliData(5) = 694 NongliData(6) = 2391 NongliData(7) = 133423 NongliData(8) = 1175 NongliData(9) = 396438 NongliData(10) = 3402 NongliData(11) = 3749 NongliData(12) = 331177 NongliData(13) = 1453 NongliData(14) = 694 NongliData(15) = 201326NongliData(17) = 465197 NongliData(18) = 3221 NongliData(19) = 3402 NongliData(20) = 400202 NongliData(21) = 2901 NongliData(22) = 1386 NongliData(23) = 267611 NongliData(24) = 605 NongliData(25) = 2349 NongliData(26) = 137515 NongliData(27) = 2709 NongliData(28) = 464533 NongliData(29) = 1738 NongliData(30) = 2901 NongliData(31) = 330421 NongliData(32) = 1242 NongliData(33) = 2651 NongliData(34) = 199255 NongliData(35) = 1323 NongliData(36) = 529706 NongliData(37) = 3733 NongliData(38) = 1706 NongliData(39) = 398762 NongliData(40) = 2741 NongliData(41) = 1206 NongliData(42) = 267438 NongliData(43) = 2647 NongliData(44) = 1318 NongliData(45) = 204070 NongliData(46) = 3477 NongliData(47) = 461653 NongliData(48) = 1386 NongliData(49) = 2413 NongliData(50) = 330077 NongliData(51) = 1197 NongliData(52) = 2637 NongliData(53) = 268877 NongliData(54) = 3365 NongliData(55) = 531109 NongliData(56) = 2900 NongliData(57) = 2922 NongliData(58) = 398042 NongliData(59) = 2395NongliData(61) = 267415NongliData(62) = 2635NongliData(63) = 661067NongliData(64) = 1701NongliData(65) = 1748NongliData(66) = 398772NongliData(67) = 2742NongliData(68) = 2391NongliData(69) = 330031NongliData(70) = 1175NongliData(71) = 1611NongliData(72) = 200010NongliData(73) = 3749NongliData(74) = 527717NongliData(75) = 1452NongliData(76) = 2742NongliData(77) = 332397NongliData(78) = 2350NongliData(79) = 3222NongliData(80) = 268949NongliData(81) = 3402NongliData(82) = 3493NongliData(83) = 133973NongliData(84) = 1386NongliData(85) = 464219NongliData(86) = 605NongliData(87) = 2349NongliData(88) = 334123NongliData(89) = 2709NongliData(90) = 2890NongliData(91) = 267946NongliData(92) = 2773NongliData(93) = 592565NongliData(94) = 1210NongliData(95) = 2651NongliData(96) = 395863NongliData(97) = 1323NongliData(98) = 2707NongliData(99) = 265877'生成当前公历年、月、日==> GongliStr curYear = Year(curTime)curMonth = Month(curTime)curDay = Day(curTime)GongliStr = curYear & "年"If (curMonth < 10) ThenGongliStr = GongliStr & "0" & curMonth & "月"ElseGongliStr = GongliStr & curMonth & "月"End IfIf (curDay < 10) ThenGongliStr = GongliStr & "0" & curDay & "日"ElseGongliStr = GongliStr & curDay & "日"End If'计算到初始时间1921年2月8日的天数:1921-2-8(正月初一)TheDate = (curYear - 1921) * 365 + Int((curYear - 1921) / 4) + curDay + MonthAdd(curMonth - 1) - 38If ((curYear Mod 4) = 0 And curMonth > 2) ThenTheDate = TheDate + 1End If'计算农历天干、地支、月、日isEnd = 0m = 0DoIf (NongliData(m) < 4095) Thenk = 11Elsek = 12End Ifn = kDoIf (n < 0) ThenExit DoEnd If'获取NongliData(m)的第n个二进制位的值bit = NongliData(m)For i = 1 To n Step 1bit = Int(bit / 2)Nextbit = bit Mod 2If (TheDate <= 29 + bit) ThenisEnd = 1Exit DoEnd IfTheDate = TheDate - 29 - bitn = n - 1LoopIf (isEnd = 1) ThenExit DoEnd Ifm = m + 1LoopcurYear = 1921 + mcurMonth = k - n + 1curDay = TheDateIf (k = 12) ThenIf (curMonth = (Int(NongliData(m) / 65536) + 1)) ThencurMonth = 1 - curMonthElseIf (curMonth > (Int(NongliData(m) / 65536) + 1)) ThencurMonth = curMonth - 1End IfEnd If'生成农历天干、地支、属相==> NongliStrNongliStr = "农历" & TianGan(((curYear - 4) Mod 60) Mod 10) & DiZhi(((curYear - 4) Mod 60) Mod 12) & "年"NongliStr = NongliStr & "(" & ShuXiang(((curYear - 4) Mod 60) Mod 12) & ")"'生成农历月、日==> NongliDayStrIf (curMonth < 1) ThenNongliDayStr = "闰" & MonName(-1 * curMonth)ElseNongliDayStr = MonName(curMonth)End IfNongliDayStr = NongliDayStr & "月"NongliDayStr = NongliDayStr & DayName(curDay)NongLi = NongliStr & NongliDayStrEnd Function步骤2,单击窗口右上角的“关闭”按钮关闭VBA编辑窗口,返回到工作表窗口中。

Excel的公历与农历转换

Excel的公历与农历转换
/Article/ShowArticle.asp?ArticleID=249(第 1/7 页)2005-11-7 22:20:36
公历与农历的转换
DiZhi(8) = "申" DiZhi(9) = "酉" DiZhi(10) = "戌" DiZhi(11) = "亥" '属相名称 ShuXiang(0) = "鼠" ShuXiang(1) = "牛" ShuXiang(2) = "虎" ShuXiang(3) = "兔" ShuXiang(4) = "龙" ShuXiang(5) = "蛇" ShuXiang(6) = "马" ShuXiang(7) = "羊" ShuXiang(8) = "猴" ShuXiang(9) = "鸡" ShuXiang(10) = "狗" ShuXiang(11) = "猪" '农历日期名 DayName(0) = "*" DayName(1) = "初一" DayName(2) = "初二" DayName(3) = "初三" DayName(4) = "初四" DayName(5) = "初五" DayName(6) = "初六" DayName(7) = "初七" DayName(8) = "初八" DayName(9) = "初九" DayName(10) = "初十" DayName(11) = "十一" DayName(12) = "十二" DayName(13) = "十三" DayName(14) = "十四" DayName(15) = "十五" DayName(16) = "十六" DayName(17) = "十七" DayName(18) = "十八" DayName(19) = "十九" DayName(20) = "二十" DayName(21) = "廿一" DayName(22) = "廿二" DayName(23) = "廿三" DayName(24) = "廿四" DayName(25) = "廿五" DayName(26) = "廿六" DayName(27) = "廿七" DayName(28) = "廿八" DayName(29) = "廿九" DayName(30) = "三十" '农历月份名 MonName(0) = "*" MonName(1) = "正" MonName(2) = "二" MonName(3) = "三" MonName(4) = "四" MonName(5) = "五" MonName(6) = "六"

Excel中阳历转阴历的处理技巧-日历模板(2)

Excel中阳历转阴历的处理技巧-日历模板(2)

Excel中阳历转阴历的处理技巧-日历模板(2)使用Excel函数制作一个2023年日历(1)今天我们介绍日历制作中的日程及阴历处理。

日程及节假日安排先来看日程以及节假日安排。

上图是日程数据以及节假日和调休的数据,都记录在超级表中。

剩下的事情就是在日历当中进行展示在全年的日历当中展示很容易,只要用条件格式,将对应日期在表中用VLOOKUP函数检查,只要找到了活动这一列不为空,不返回错误值,那么就表示它有一个日程,就可以给单元格变色。

节假日也是如此,在节假日表中查找相应的日期,返回第二列,如果不返回错误值并且不返回空白单元格,就表该天是节假日,需要变色。

周末上班也是同样的方法。

在单月日历中显示需要用另外的逻辑,我们后面介绍。

阴历处理Excel提供了一种很简单的方式:自定义格式,来帮助我们将阳历转为阴历。

所以,我们可以通过TEXT函数来实现转换:•••lunar_day, TEXT(theday, "[$-130000]d"),lunar_month, TEXT(theday, "[$-13000]m"),lunar_year, TEXT(theday, "[$-13000]yyyy") 我们将一个标准日期转换为阴历的日,月,年。

但是工作并没有完成,因为这么转换后有几个问题:1.日期处理:转换后的日是1,2,3,4,....,但是日历中需要显示为大写,比如11,应该显示为十一,这可以通过隐藏函数NUMBERSTRING来实现。

不过还需要进行仔细处理:a.1~10之间的日期应该显示为初一~初十b.11~19转为大写后,显示为一十一等,应该去掉开始的一,显示为十一c.20~29转为大写后,显示为二十一等,但是中文习惯上写作廿一d.每月1号应该显示为月份,而不是初一2.月份处理:转换后的月份为1,2,3,4,5,... 12,13。

大写后是一,二,......,十,一十一,一十二,一十三等。

excel公历转农历的四种方法

excel公历转农历的四种方法

excel公历转农历的四种方法excel公历转农历方法一:使用text函数A列是公历日期,我们在B1单元格输入公式:=TEXT(A1,"[$-130000]yyyy年m月"&I F(LEN(--TEXT(A1,"[$-130000]dd"))=1,"初","")&"d"),下拉完成公历转农历。

excel公历转农历方法二:使用text+MID函数A列仍然是公历,B1输入公式:=MID("甲乙丙丁戊己庚辛壬癸",MOD(TEXT(A1,"[$-13 0000]e")-4,10)+1,1)&MID("子丑寅卯辰巳午未申酉戌亥",MOD(TEXT(A1,"[$-130000]e")-4, 12)+1,1)&"年"&TEXT(A1,"[$-130000][DBNum1]m月d日"即可。

excel公历转农历方法三:使用text+MID+ CHOOSE+ YEAR函数A1为公历,B1输入:=CHOOSE(MOD(YEAR(A1)-1900,10)+1,"庚","辛","壬","癸","甲", "乙","丙","丁","戊","己")&CHOOSE(MOD(YEAR(A1)-1900,12)+1,"子","丑","寅","卯","辰","巳","午","未","申","酉","戌","亥")&TEXT(A1,"[dbnum1][$-130000]年m月"&IF(--TEXT(A1, "[$-130000]d")<11,"初","")&TEXT(A1,"[dbnum1][$-130000]d"))excel公历转农历方法四:使用自定义函数上面介绍的excel公历转农历都是使用excel内置函数完成的,有一个弊端就是公式太长,如果使用自定义函数,在公式栏就可以简化输入。

一键转换,公历转农历只要一个公式,超简单

一键转换,公历转农历只要一个公式,超简单

⼀键转换,公历转农历只要⼀个公式,超简单私信回复关键词【学⼀招】,⼀次性 Get 学⼀招合集!助你成为⾼效职场⼈!
分不清「公历」和「农历」的烦恼⽆处不在。

⽐如从⼩只过「公历」⽣⽇的⼩ E,⾝边有⼀⼤群只过「农历」⽣⽇的朋友。

每次⼩ E 都要翻
N 遍黄历,以确保不在错误的时间送上祝福。

还有过年放假,家⾥⼈总说「初三去⼤姨那⼉拜年,初四去⼤姑家」。

⼩E只能看着台历,从⼤
年三⼗数到正⽉初三。

再⽐如⼀直认为农历七⼣指的是 7 ⽉ 7 ⽇。

……
如果你也有类似的烦恼,那么今天要学的这⼀招,⼀定能帮上你——⽤ Excel 将公历转农历!
公历转农历只需要⼀个简单的公式:
=TEXT(A2,'[$-130000]yyyy-m-d')
其中,A2 表⽰要转化的公历⽇期;
yyyy-m-d 表⽰输⼊⽇期的格式;
[$-130000] 是表⽰公历转阴历的特殊参数。

操作⽅法:
❶先点选单元格,输⼊上述公式:
❷输⼊完公式后,只要按下【回车】键,再双击单元格右下⾓的「填充柄」,快速填充,对应
的农历⽇期就全部转换完成!
例如:今天是公历 2019/7/3,那么对应的农历⽇期就为 2019-6-1:
美中不⾜的是,该公式只适⽤于 Excel 2010 以上的版本,且⽆法计算出闰⽉。

wps公历转农历的四种方法

wps公历转农历的四种方法

wps公历转农历的四种方法
公历转农历的方法有以下四种:
1. 查农历日历:可以在书店或网络上找到农历日历,根据公历日期查找对应的农历日期。

2. 在线查询:很多网站提供公历转农历的查询服务,只需要输入公历日期即可查询对应的农历日期。

3. 使用农历算法:农历算法比较复杂,但是可以通过计算出该年的元旦是农历几月几日以及公历日期与元旦的天数差来计算出对应的农历日期。

4. 下载农历日历应用:很多手机应用市场提供了农历日历应用,用户只需要输入公历日期即可查询对应的农历日期。

公历与农历自动转化表格

公历与农历自动转化表格

公历与农历自动转化表格公历与农历的转换涉及到农历的闰月和年份的差异,因此需要使用一些特殊的计算方法。

以下是一个简单的公历与农历自动转化的表格,你可以在Excel等表格软件中使用:
在这个表格中,"公历日期"列是公历日期,"农历日期"列是对应的农历日期。

请注意,这只是一个简化的示例,实际上,要实现精确的公历与农历转化可能需要使用专业的农历计算库或算法。

如果你需要实现更复杂的公历与农历转化功能,建议使用专业的日期计算库或在线工具,这样可以确保准确性和可靠性。

1/ 1。

阴历阳历转换算法

阴历阳历转换算法

阴历阳历转换算法一、阳历转农历算法阳历转农历的算法可以分为两种:数学计算法和查表法。

1.数学计算法阳历转农历的数学计算法基于一些数学公式和推算规则。

其中,公历年份、月份和日期的确定使用了基于蔡勒公式、游戏二法和公式等方式。

核心计算公式:(1)蔡勒公式:W=(C/4-2*C+y+y/4+13*(m+1)/5+d-1)%7其中,W为一周中的日期,C为世纪数,y为年份的后两位数,m为月份(1代表3月,2代表4月,依此类推),d为公历日期。

其中,jdy为公历日期的数值。

M=[N/1461]D = N mod 1461K=[D/365](4)数学计算方法计算公历日期对应的年份、月份和日期。

2.查表法阳历转农历的查表法使用一个双向映射表,将公历日期和农历日期进行映射。

这样,当需要进行阳历转农历时,只需要在该表中查找对应的日期。

该表通常包括每个公历年份的月份和日期,以及相应的农历月份和日期。

二、农历转阳历算法农历转阳历的算法也可以使用数学计算法和查表法。

1.数学计算法农历转阳历的数学计算法基于一定的规则和公式。

其中,农历年份、月份和日期的确定使用了一些数学公式。

核心计算公式:(1)计算春节对应的公历日期:N=y*365+[y/4]-[y/100]+[y/400]+[30.6*(m+0.5)]+d-1899.5其中,N为公历日期的数值。

(2)根据公历日期的数值,计算农历日期的年份、月份和日期。

2.查表法农历转阳历的查表法使用一个双向映射表,将农历日期和公历日期进行映射。

这样,当需要进行农历转阳历时,只需要在该表中查找对应的日期。

该表通常包括每个农历年份的月份和日期,以及相应的公历月份和日期。

三、应用阳历转农历和农历转阳历算法广泛应用于日历、生活工具、节日计算等方面。

在计算机程序和手机应用中,这些算法可以用来进行日期转换、节日提醒等功能。

此外,还有一些相对复杂的算法可以使用天文计算和历法知识,考虑到地球的自转、公转、地球轨道等因素来进行日期转换,提高转换的准确性。

excel中农历国历的相互转换方法及代码

excel中农历国历的相互转换方法及代码

打开相应的excel表格,按Alt+F11打开VBA编辑器,点击插入—插入模块,将下面代码粘贴上去,点击保存后关闭该窗口。

接着在相应单元格调用下面四个函数即可实现相应的功能了。

适用于1901-2100年间=lunar("2006-11-1") 求阳历2006-11-1日对应的阴历=solar("2006-1-1") 求阴历2006年正月初一对应的阳历=lunarbirth("1975-5-6") 阴历生日:阳历1975年5月6日出生,今年阴历生日时对应的阳历日期=solarbirth("1975-5-6") 阳历生日:阳历1975年5月6日出生,今年阳历生日时对应的阳历日期1.'阴阳历转换和阴阳历生日2.'Version: 1.1 2005-9-13.'Author: James Zhuang4.'Lunar(SolarDate[, Part = 0 | 1 | 2 | 3]) 阳历转换成阴历5.' Part = 0, all; Part = 1, lunar year; Part = 2, lunarmonth; Part = 3, lunar day6.'Solar(LunarDate[, LunarMonth = 0 | 1]) 阴历转换成阳历7.Type ConvDataA8. leapmonth As Integer9. month(1 To 13) As Integer10. sp_month As Integer 'Solar month of Spring Festival11. sp_day As Integer 'Solar day of Spring Festival12.End Type13.Private Function LunarData(q_year) As ConvDataA14. Dim d As Long15. Dim month(1 To 13) As Integer16.'1901-210017.LunarCal = Array(&H4AE53, &HA5748, &H5526BD, &HD2650, &HD9544, &H46AAB9, &H56A4D,&H9AD42, &H24AEB6, &H4AE4A, _18.&H6A4DBE, &HA4D52, &HD2546, &H5D52BA, &HB544E, &HD6A43, &H296D37, &H95B4B,&H749BC1, &H49754, _19.&HA4B48, &H5B25BC, &H6A550, &H6D445, &H4ADAB8, &H2B64D, &H95742, &H2497B7,&H4974A, &H664B3E, _20.&HD4A51, &HEA546, &H56D4BA, &H5AD4E, &H2B644, &H393738, &H92E4B, &H7C96BF,&HC9553, &HD4A48, _21.&H6DA53B, &HB554F, &H56A45, &H4AADB9, &H25D4D, &H92D42, &H2C95B6, &HA954A,&H7B4ABD, &H6CA51, _22.&HB5546, &H555ABB, &H4DA4E, &HA5B43, &H352BB8, &H52B4C, &H8A953F, &HE9552,&H6AA48, &H7AD53C, _23.&HAB54F, &H4B645, &H4A5739, &HA574D, &H52642, &H3E9335, &HD9549, &H75AABE,&H56A51, &H96D46, _24.&H54AEBB, &H4AD4F, &HA4D43, &H4D26B7, &HD254B, &H8D52BF, &HB5452, &HB6A47,&H696D3C, &H95B50, _25.&H49B45, &H4A4BB9, &HA4B4D, &HAB25C2, &H6A554, &H6D449, &H6ADA3D, &HAB651,&H93746, &H5497BB, _26.&H4974F, &H64B44, &H36A537, &HEA54A, &H86B2BF, &H5AC53, &HAB647, &H5936BC,&H92E50, &HC9645, _27.&H4D4AB8, &HD4A4C, &HDA541, &H25AA36, &H56A49, &H7AADBD, &H25D52, &H92D47,&H5C95BA, &HA954E, _28.&HB4A43, &H4B5537, &HAD54A, &H955ABF, &H4BA53, &HA5B48, &H652BBC, &H52B50,&HA9345, &H474AB9, _29.&H6AA4C, &HAD541, &H24DAB6, &H4B64A, &H69573D, &HA4E51, &HD2646, &H5E933A,&HD534D, &H5AA43, _30.&H36B537, &H96D4B, &HB4AEBF, &H4AD53, &HA4D48, &H6D25BC, &HD254F, &HD5244,&H5DAA38, &HB5A4C, _31.&H56D41, &H24ADB6, &H49B4A, &H7A4BBE, &HA4B51, &HAA546, &H5B52BA, &H6D24E,&HADA42, &H355B37, _32.&H9374B, &H8497C1, &H49753, &H64B48, &H66A53C, &HEA54F, &H6B244, &H4AB638,&HAAE4C, &H92E42, _33.&H3C9735, &HC9649, &H7D4ABD, &HD4A51, &HDA545, &H55AABA, &H56A4E, &HA6D43,&H452EB7, &H52D4B, _34.&H8A95BF, &HA9553, &HB4A47, &H6B553B, &HAD54F, &H55A45, &H4A5D38, &HA5B4C,&H52B42, &H3A93B6, _35.&H69349, &H7729BD, &H6AA51, &HAD546, &H54DABA, &H4B64E, &HA5743, &H452738,&HD264A, &H8E933E, _36.&HD5252, &HDAA47, &H66B53B, &H56D4F, &H4AE45, &H4A4EB9, &HA4D4C, &HD1541,&H2D92B5, &HD5349)37.startyear = 190138.ng = LunarCal(q_year - startyear)39. d = &H10000040. LunarData.leapmonth = Int(ng / d)41. ng = ng Mod d42. d = &H8043. mdata = Int(ng / d)44. ng = ng Mod d45. d = &H2046. LunarData.sp_month = Int(ng / d)47. LunarData.sp_day = ng Mod d48. d = &H100049. i = 150. Do51. LunarData.month(i) = 29 + Int(mdata / d)52. mdata = mdata Mod d53. If d = 1 Then Exit Do54. d = d / 255. i = i + 156. Loop57. If LunarData.leapmonth = 0 Then LunarData.month(i) = 058.End Function59.Function lunar(Solar_date As Date, Optional Part As Integer = 0) As String60.'Part = 0, all; Part = 1, lunar year; Part = 2, lunar month; Part = 3, lunar day61.Dim a As ConvDataA62.l_year = Year(Solar_date)63.a = LunarData(l_year)64.sp_date = DateSerial(l_year, a.sp_month, a.sp_day)65.If sp_date > Solar_date Then66. l_year = l_year - 167. a = LunarData(l_year)68. sp_date = DateSerial(l_year, a.sp_month, a.sp_day)69.End If70.l_day = Solar_date - sp_date71.l_month = 172.IS_lunar_leapmonth = False73.y = a.month(l_month)74.Do While l_day >= y75. l_day = l_day - y76. If l_month = a.leapmonth Then IS_lunar_leapmonth = (Not IS_lunar_leapmonth)77. If IS_lunar_leapmonth Then78. y = a.month(13)79. Else80. l_month = l_month + 181. y = a.month(l_month)82. End If83.Loop84.l_day = l_day + 185.lunar = l_year & "-" & l_month & "-" & l_day86.If IS_lunar_leapmonth Then lunar = lunar & "-L"87.lunar = Choose(Part + 1, lunar, l_year, l_month, l_day)88.End Function89.Function solar(Lunar_date, Optional IS_lunar_leapmonth As Integer = 0) As String90.'IS_lunar_leapmonth = 0, No leap month; IS_lunar_leapmonth = 1, is leap month91.Dim a As ConvDataA92.Lunar_date = Split(Lunar_date, "-")93.s_year = Lunar_date(0)94.For Each C In Lunar_date95. If C = "L" Then IS_lunar_leapmonth = 196.Next97.a = LunarData(s_year)98.sp_date = DateSerial(s_year, a.sp_month, a.sp_day)99.If Lunar_date(1) <> a.leapmonth Then IS_lunar_leapmonth = 0100.x = Lunar_date(2)101.tm = Lunar_date(1) + IS_lunar_leapmonth - 1102.For i = 1 To tm103. x = x + a.month(i)104. If i = a.leapmonth And IS_lunar_leapmonth = 0 Then105. x = x + a.month(13)106. End If107.Next108.s_date = sp_date + x - 1109.solar = s_date110.End Function111.Function lunarbirth(Solar_birthday As Date, Optional Inquire_year As Integer) As String112. If Inquire_year = 0 Then113. Inquire_year = Left(lunar(Now), 4)114. lunarbirth = solar(Inquire_year & Mid(lunar(Solar_birthday), 5, 10)) 115. If CDate(lunarbirth) < Now - 1 Then Inquire_year = Inquire_year + 1 116. End If117. lunarbirth = solar(Inquire_year & Mid(lunar(Solar_birthday), 5, 10)) 118.End Function119.Function solarbirth(Solar_birthday As Date, Optional Inquire_year As Integer) As String120. If Inquire_year = 0 Then121. Inquire_year = Year(Now)122. solarbirth = DateSerial(Inquire_year, month(Solar_birthday), Day(Solar_birthday))123. If CDate(solarbirth) < Now - 1 Then Inquire_year = Inquire_year + 1 124. End If125. solarbirth = DateSerial(Inquire_year, month(Solar_birthday), Day(Solar_birthday))126.End Function。

excel国历转农历表格

excel国历转农历表格

excel国历转农历表格
要将Excel中的公历日期转换为农历日期,通常需要使用宏或
公式来实现。

以下是一种常见的方法:
1. 首先,你需要在Excel中安装农历插件或者使用VBA宏来实
现公历到农历的转换。

如果你不熟悉VBA,可以在网上搜索并下载
农历插件,然后安装到Excel中。

2. 一旦安装好了插件或者准备好了VBA宏,你就可以使用公历
日期的单元格作为输入,然后在相应的农历日期单元格中得到转换
后的结果。

3. 如果你选择使用VBA宏,你可以编写一个简单的VBA函数来
实现公历转农历的功能。

这需要一定的VBA编程知识,但是一旦编
写完成,你就可以在Excel中直接调用这个函数来实现日期的转换。

4. 另一种方法是使用在线的农历转换工具,将公历日期转换为
农历日期,然后手动输入到Excel中。

这种方法虽然不够自动化,
但对于简单的转换任务可能会更加方便。

总之,要在Excel中将公历日期转换为农历日期,你可以选择安装插件、编写VBA宏或者使用在线工具来实现。

希望这些方法能够帮到你。

excel公历转农历的四种方法

excel公历转农历的四种方法

excel公历转农历的四种方法excel公历转农历方法一:使用text函数A列是公历日期,我们在B1单元格输入公式:=TEXT(A1,"[$-130000]yyyy年m月"&I F(LEN(--TEXT(A1,"[$-130000]dd"))=1,"初","")&"d"),下拉完成公历转农历。

excel公历转农历方法二:使用text+MID函数A列仍然是公历,B1输入公式:=MID("甲乙丙丁戊己庚辛壬癸",MOD(TEXT(A1,"[$-13 0000]e")-4,10)+1,1)&MID("子丑寅卯辰巳午未申酉戌亥",MOD(TEXT(A1,"[$-130000]e")-4, 12)+1,1)&"年"&TEXT(A1,"[$-130000][DBNum1]m月d日"即可。

excel公历转农历方法三:使用text+MID+ CHOOSE+ YEAR函数A1为公历,B1输入:=CHOOSE(MOD(YEAR(A1)-1900,10)+1,"庚","辛","壬","癸","甲", "乙","丙","丁","戊","己")&CHOOSE(MOD(YEAR(A1)-1900,12)+1,"子","丑","寅","卯","辰","巳","午","未","申","酉","戌","亥")&TEXT(A1,"[dbnum1][$-130000]年m月"&IF(--TEXT(A1, "[$-130000]d")<11,"初","")&TEXT(A1,"[dbnum1][$-130000]d"))excel公历转农历方法四:使用自定义函数上面介绍的excel公历转农历都是使用excel内置函数完成的,有一个弊端就是公式太长,如果使用自定义函数,在公式栏就可以简化输入。

公历换算农历公式

公历换算农历公式

公历换算农历公式
公历换算农历公式
想要将公历转换为农历,可以根据公式:公元年数—1901(或1977)=R+4Q;那么农历日期=10.6(1+R)+14Q+年内日期序数—29.5n(n、R、Q都是自然数,R<4)。

这个公式算法对于很多数学不好的人而言是很费脑子的,算大半天也算不出来,而当今科技是比较发达的,我们想要将进行公农历转换并不需要这么复杂的计算。

现在,想要将公农历进行转换方法很简单,比较传统的一个方法就是可以直接看挂历或是台历,上面每个公历日期的下面都会标注都相对应的农历日期,我们只需一翻阅就能查询到公历相对应的农历日期了。

比如我们要看2021年7月2日的农历日期,7月2日的下面就会显示农历日期为五月廿三。

对于公农历转换公式是什么,我们已经了解了,但是它的是比较复杂的,而现在是网络普及的一个时代,平板、手机以及电脑等等电子产品也都设置有万年历这中功能,所以对于公历与农历的转换,一查看就可以了,很方便。

并且与传统的挂历、台历本子而言,电子设备上的日期不局限于一年的日期,这给人们的生活、学习以及日常工作等更方便。

好了,公历是国际通过的历法,当年日期的记录均是以阳历为准,但农历是我国传统的一种日期记录方式,在实际上生活中难免会用到公农历转换。

我们知道公农历转换公式是什么,但是算法复杂,我们大可不必去计算,看挂历即可。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

excel公历转农历的四种方法[日期:2012-02-08] 来源:IT部落窝作者:IT部落窝阅读:8875次[字体:大中小]内容提要:文章介绍excel公历转农历的四种方法,分别通过excel内置函数和自定义函数完成公历转农历。

尽管通过很多渠道可以轻松获取公历转农历,但是对excel迷们还是很期待用excel来实现公历转农历。

设想一下,IT部落窝会员们的信息都是以阳历注册的,我们也可以使用下面即将介绍的方法实现excel公历转农历。

excel公历转农历方法一:使用text函数A列是公历日期,我们在B1单元格输入公式:=TEXT(A1,"[$-130000]yyyy年m月"&I F(LEN(--TEXT(A1,"[$-130000]dd"))=1,"初","")&"d"),下拉完成公历转农历。

excel公历转农历方法二:使用text+MID函数A列仍然是公历,B1输入公式:=MID("甲乙丙丁戊己庚辛壬癸",MOD(TEXT(A1,"[$-13 0000]e")-4,10)+1,1)&MID("子丑寅卯辰巳午未申酉戌亥",MOD(TEXT(A1,"[$-130000]e")-4, 12)+1,1)&"年"&TEXT(A1,"[$-130000][DBNum1]m月d日"即可。

excel公历转农历方法三:使用text+MID+ CHOOSE+ YEAR函数A1为公历,B1输入:=CHOOSE(MOD(YEAR(A1)-1900,10)+1,"庚","辛","壬","癸","甲", "乙","丙","丁","戊","己")&CHOOSE(MOD(YEAR(A1)-1900,12)+1,"子","丑","寅","卯","辰","巳","午","未","申","酉","戌","亥")&TEXT(A1,"[dbnum1][$-130000]年m月"&IF(--TEXT(A1, "[$-130000]d")<11,"初","")&TEXT(A1,"[dbnum1][$-130000]d"))excel公历转农历方法四:使用自定义函数上面介绍的excel公历转农历都是使用excel内置函数完成的,有一个弊端就是公式太长,如果使用自定义函数,在公式栏就可以简化输入。

如下图所示,我们在B2输入公式:=nongli(A2),即可。

C列农历简称中C2公式是:=RIGHT(B2,LEN(B2)-8)。

关于自定义函数的使用方法请参考:excel自定义函数添加和使用方法下面是此自定义函数相关的代码:Public Function NongLi(Optional XX_DATE As Date)Dim MonthAdd(11), NongliData(99), TianGan(9), DiZhi(11), ShuXiang(11), DayName(3 0), MonName(12)Dim curTime, curYear, curMonth, curDayDim GongliStr, NongliStr, NongliDayStrDim i, m, n, k, isEnd, bit, TheDate'获取当前系统时间curTime = XX_DATE'天干名称TianGan(0) = "甲"TianGan(1) = "乙"TianGan(2) = "丙"TianGan(3) = "丁" TianGan(4) = "戊" TianGan(5) = "己" TianGan(6) = "庚" TianGan(7) = "辛" TianGan(8) = "壬" TianGan(9) = "癸"'地支名称DiZhi(0) = "子" DiZhi(1) = "丑" DiZhi(2) = "寅" DiZhi(3) = "卯" DiZhi(4) = "辰" DiZhi(5) = "巳" DiZhi(6) = "午" DiZhi(7) = "未" DiZhi(8) = "申" DiZhi(9) = "酉" DiZhi(10) = "戌" DiZhi(11) = "亥"'属相名称ShuXiang(0) = "鼠" ShuXiang(1) = "牛" ShuXiang(2) = "虎" ShuXiang(3) = "兔" ShuXiang(4) = "龙" ShuXiang(5) = "蛇" ShuXiang(6) = "马" ShuXiang(7) = "羊" ShuXiang(8) = "猴" ShuXiang(9) = "鸡" ShuXiang(10) = "狗" ShuXiang(11) = "猪" '农历日期名DayName(0) = "*" DayName(1) = "初一" DayName(2) = "初二" DayName(3) = "初三" DayName(4) = "初四" DayName(5) = "初五" DayName(6) = "初六" DayName(7) = "初七" DayName(8) = "初八" DayName(9) = "初九"DayName(10) = "初十" DayName(11) = "十一" DayName(12) = "十二" DayName(13) = "十三" DayName(14) = "十四" DayName(15) = "十五" DayName(16) = "十六" DayName(17) = "十七" DayName(18) = "十八" DayName(19) = "十九" DayName(20) = "二十" DayName(21) = "廿一" DayName(22) = "廿二" DayName(23) = "廿三" DayName(24) = "廿四" DayName(25) = "廿五" DayName(26) = "廿六" DayName(27) = "廿七" DayName(28) = "廿八" DayName(29) = "廿九" DayName(30) = "三十" '农历月份名MonName(0) = "*" MonName(1) = "正" MonName(2) = "二" MonName(3) = "三" MonName(4) = "四" MonName(5) = "五" MonName(6) = "六" MonName(7) = "七" MonName(8) = "八" MonName(9) = "九" MonName(10) = "十" MonName(11) = "十一" MonName(12) = "腊" '公历每月前面的天数MonthAdd(0) = 0 MonthAdd(1) = 31 MonthAdd(2) = 59 MonthAdd(3) = 90 MonthAdd(4) = 120 MonthAdd(5) = 151 MonthAdd(6) = 181 MonthAdd(7) = 212MonthAdd(8) = 243 MonthAdd(9) = 273 MonthAdd(10) = 304 MonthAdd(11) = 334'农历数据NongliData(0) = 2635 NongliData(1) = 333387 NongliData(2) = 1701 NongliData(3) = 1748 NongliData(4) = 267701 NongliData(5) = 694 NongliData(6) = 2391 NongliData(7) = 133423 NongliData(8) = 1175 NongliData(9) = 396438 NongliData(10) = 3402 NongliData(11) = 3749 NongliData(12) = 331177 NongliData(13) = 1453 NongliData(14) = 694 NongliData(15) = 201326 NongliData(16) = 2350 NongliData(17) = 465197 NongliData(18) = 3221 NongliData(19) = 3402 NongliData(20) = 400202 NongliData(21) = 2901 NongliData(22) = 1386 NongliData(23) = 267611 NongliData(24) = 605 NongliData(25) = 2349 NongliData(26) = 137515 NongliData(27) = 2709 NongliData(28) = 464533 NongliData(29) = 1738 NongliData(30) = 2901 NongliData(31) = 330421 NongliData(32) = 1242 NongliData(33) = 2651 NongliData(34) = 199255 NongliData(35) = 1323 NongliData(36) = 529706 NongliData(37) = 3733 NongliData(38) = 1706NongliData(40) = 2741 NongliData(41) = 1206 NongliData(42) = 267438 NongliData(43) = 2647 NongliData(44) = 1318 NongliData(45) = 204070 NongliData(46) = 3477 NongliData(47) = 461653 NongliData(48) = 1386 NongliData(49) = 2413 NongliData(50) = 330077 NongliData(51) = 1197 NongliData(52) = 2637 NongliData(53) = 268877 NongliData(54) = 3365 NongliData(55) = 531109 NongliData(56) = 2900 NongliData(57) = 2922 NongliData(58) = 398042 NongliData(59) = 2395 NongliData(60) = 1179 NongliData(61) = 267415 NongliData(62) = 2635 NongliData(63) = 661067 NongliData(64) = 1701 NongliData(65) = 1748 NongliData(66) = 398772 NongliData(67) = 2742 NongliData(68) = 2391 NongliData(69) = 330031 NongliData(70) = 1175 NongliData(71) = 1611 NongliData(72) = 200010 NongliData(73) = 3749 NongliData(74) = 527717 NongliData(75) = 1452 NongliData(76) = 2742 NongliData(77) = 332397 NongliData(78) = 2350 NongliData(79) = 3222 NongliData(80) = 268949 NongliData(81) = 3402 NongliData(82) = 3493NongliData(84) = 1386NongliData(85) = 464219NongliData(86) = 605NongliData(87) = 2349NongliData(88) = 334123NongliData(89) = 2709NongliData(90) = 2890NongliData(91) = 267946NongliData(92) = 2773NongliData(93) = 592565NongliData(94) = 1210NongliData(95) = 2651NongliData(96) = 395863NongliData(97) = 1323NongliData(98) = 2707NongliData(99) = 265877'生成当前公历年、月、日==>GongliStrcurYear = Year(curTime)curMonth = Month(curTime)curDay = Day(curTime)GongliStr = curYear& "年"If (curMonth< 10) ThenGongliStr = GongliStr& "0" &curMonth& "月"ElseGongliStr = GongliStr&curMonth& "月"End IfIf (curDay< 10) ThenGongliStr = GongliStr& "0" &curDay& "日"ElseGongliStr = GongliStr&curDay& "日"End If'计算到初始时间1921年2月8日的天数:1921-2-8(正月初一)TheDate = (curYear - 1921) * 365 + Int((curYear - 1921) / 4) + curDay + Month Add(curMonth - 1) - 38If ((curYear Mod 4) = 0 And curMonth> 2) ThenTheDate = TheDate + 1End If'计算农历天干、地支、月、日isEnd = 0m = 0DoIf (NongliData(m) < 4095) Thenk = 11Elsek = 12End Ifn = kDoIf (n < 0) ThenExit DoEnd If'获取NongliData(m)的第n个二进制位的值bit = NongliData(m)For i = 1 To n Step 1bit = Int(bit / 2)Nextbit = bit Mod 2If (TheDate<= 29 + bit) ThenisEnd = 1Exit DoEnd IfTheDate = TheDate - 29 - bitn = n - 1LoopIf (isEnd = 1) ThenExit DoEnd Ifm = m + 1LoopcurYear = 1921 + mcurMonth = k - n + 1curDay = TheDateIf (k = 12) ThenIf (curMonth = (Int(NongliData(m) / 65536) + 1)) ThencurMonth = 1 - curMonthElseIf (curMonth> (Int(NongliData(m) / 65536) + 1)) ThencurMonth = curMonth - 1End IfEnd If'生成农历天干、地支、属相==>NongliStrNongliStr = "农历" &TianGan(((curYear - 4) Mod 60) Mod 10) &DiZhi(((curYear - 4) Mod 60) Mod 12) & "年"NongliStr = NongliStr& "(" &ShuXiang(((curYear - 4) Mod 60) Mod 12) & ")"'生成农历月、日==>NongliDayStrIf (curMonth< 1) ThenNongliDayStr = "闰" &MonName(-1 * curMonth)ElseNongliDayStr = MonName(curMonth)End IfNongliDayStr = NongliDayStr& "月" NongliDayStr = NongliDayStr&DayName(curDay)NongLi = NongliStr&NongliDayStrEnd Function。

相关文档
最新文档