excel公历转农历的四种方法
excel二进制表格
竭诚为您提供优质文档/双击可除excel二进制表格篇一:excel公历转农历的四种方法excel公历转农历的四种方法excel公历转农历方法一:使用text函数a列是公历日期,我们在b1单元格输入公式:=text(a1,"[$-130000]yyyy年m月"获取当前系统时间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)=0monthadd(1)=31monthadd(2)=59monthadd(3 )=90monthadd(4)=120monthadd(5)=151monthadd(6)=181mo nthadd(7)=212monthadd(8)=243monthadd(9)=273monthadd (10)=304monthadd(11)=334农历数据nonglidata(0)=2635nonglidata(1)=333387nonglidata(2) =1701nonglidata(3)=1748nonglidata(4)=267701nonglida ta(5)=694nonglidata(6)=2391nonglidata(7)=133423nong lidata(8)=1175nonglidata(9)=396438nonglidata(10)=3402nonglidata(11)=3749nonglidata(12)=331177nonglidata(13)=1453nong lidata(14)=694nonglidata(15)=20xx26nonglidata(16)=2 350nonglidata(17)=465197nonglidata(18)=3221nonglida ta(19)=3402nonglidata(20)=400202nonglidata(21)=2901 nonglidata(22)=1386nonglidata(23)=267611nonglidata( 24)=605nonglidata(25)=2349nonglidata(26)=137515nong lidata(27)=2709nonglidata(28)=464533nonglidata(29)= 1738nonglidata(30)=2901nonglidata(31)=330421nonglid ata(32)=1242nonglidata(33)=2651nonglidata(34)=19925 5nonglidata(35)=1323nonglidata(36)=529706nonglidata (37)=3733nonglidata(38)=1706nonglidata(39)=398762no nglidata(40)=2741nonglidata(41)=1206nonglidata(42)= 267438nonglidata(43)=2647nonglidata(44)=1318nonglid ata(45)=204070nonglidata(46)=3477nonglidata(47)=461 653nonglidata(48)=1386nonglidata(49)=2413nonglidata (50)=330077nonglidata(51)=1197nonglidata(52)=2637篇二:电子表格常用函数公式电子表格常用函数公式1.去掉最高最低分函数公式:=sum(所求单元格注:可选中拖动)—max(所选单元格注:可选中拖动)—min(所求单元格注:可选中拖动)(说明:“sum”是求和函数,“max”表示最大值,“min”表示最小值。
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[求助]在电子表格中把公历日期转换成农历与天干地支Option ExplicitDim WeekName(7), MonthAdd(11), NongliData(99), TianGan(9), DiZhi(11), ShuXiang(11), DayName(30), MonName(12)Dim curTime, curYear, curMonth, curDay, curWeekdayDim GongliStr, WeekdayStr, NongliStr, NongliDayStrDim i, m, n, k, isEnd, bit, TheDatePrivate Sub FormLoad()'获取当前系统时间curTime = Now()'星期名WeekName(0) = " * "WeekName(1) = "星期日"WeekName(2) = "星期一"WeekName(3) = "星期二"WeekName(4) = "星期三"WeekName(5) = "星期四"WeekName(6) = "星期五"WeekName(7) = "星期六"'天干名称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) = 330421NongliData(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) = 267415NongliData(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) = 2709 NongliData(90) = 2890 NongliData(91) = 267946NongliData(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'生成当前公历星期 ==> WeekdayStrcurWeekday = Weekday(curTime)WeekdayStr = WeekName(curWeekday)'计算到初始时间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)) Then curMonth = 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)MsgBox NongliStr & NongliDayStrEnd Sub。
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函数进⾏将公历⽇期转化为农历⽇期!⼀、简单版下表中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中实现阳历转化阴历
步骤一,在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的公历与农历转换
公历与农历的转换
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函数制作一个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公历转农历方法一:使用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公历转农历的四种方法
公历转农历的方法有以下四种:
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表格,按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中的公历日期转换为农历日期,通常需要使用宏或
公式来实现。
以下是一种常见的方法:
1. 首先,你需要在Excel中安装农历插件或者使用VBA宏来实
现公历到农历的转换。
如果你不熟悉VBA,可以在网上搜索并下载
农历插件,然后安装到Excel中。
2. 一旦安装好了插件或者准备好了VBA宏,你就可以使用公历
日期的单元格作为输入,然后在相应的农历日期单元格中得到转换
后的结果。
3. 如果你选择使用VBA宏,你可以编写一个简单的VBA函数来
实现公历转农历的功能。
这需要一定的VBA编程知识,但是一旦编
写完成,你就可以在Excel中直接调用这个函数来实现日期的转换。
4. 另一种方法是使用在线的农历转换工具,将公历日期转换为
农历日期,然后手动输入到Excel中。
这种方法虽然不够自动化,
但对于简单的转换任务可能会更加方便。
总之,要在Excel中将公历日期转换为农历日期,你可以选择安装插件、编写VBA宏或者使用在线工具来实现。
希望这些方法能够帮到你。
EXCEL公历日期转农历日期方法
EXCEL公历日期转农历日期方法要将EXCEL公历日期转换为农历日期,需要使用一种包含农历日历数据的公式或宏。
在新模块中,创建一个名为GetLunarDate的函数,该函数将接收公历日期作为输入,并返回对应的农历日期。
在GetLunarDate函数中,可以使用以下方法来计算农历日期:1. 首先,需要将公历日期转换成Excel所使用的日期格式。
可以使用Excel的DATE函数来实现这一点,该函数接受年、月和日作为参数,并返回相应的日期。
2. 然后,可以使用Excel的VLOOKUP函数来查找公历日期对应的农历日期。
VLOOKUP函数接受一个查找值、一个查找区域和一个列索引号作为参数,并返回查找值所在行中对应列的值。
在这种情况下,查找值是公历日期,查找区域是农历日历数据表格,并且列索引号是农历日期所在的列索引号。
3. 最后,根据返回的农历日期,可以使用Excel的TEXT函数将其转换为指定的格式。
TEXT函数接受一个日期值和一个格式字符串作为参数,并返回日期按照指定格式进行格式化后的字符串。
以下是一个示例的VBA代码,演示如何实现将EXCEL公历日期转换为农历日期的方法:```vbaFunction GetLunarDate(gregorianDate As Date) As StringDim lunarDate As StringDim gregorianDateFormatted As StringgregorianDateFormatted = Format(gregorianDate, "yyyymmdd")Dim lunarDateRange As RangeSet lunarDateRange = Worksheets("农历日历").Range("A2:B1000") ' 这里假设农历日历数据表格的范围是A2:B1000lunarDate = Application.VLookup(gregorianDateFormatted, lunarDateRange, 2, False)If Not IsError(lunarDate) ThenGetLunarDate = WorksheetFunction.Text(lunarDate, "yyyy年mm月dd日") ' 这里假设农历日期的格式为yyyy年mm月dd日ElseGetLunarDate = "无法找到对应的农历日期"End IfEnd Function```使用该函数的方法是,在Excel中输入公历日期,然后在另一个单元格中调用GetLunarDate函数来获取对应的农历日期。
excell农历和公历转换公式
excell农历和公历转换公式Excel是一款功能强大的电子表格软件,它不仅可以用于数据统计和分析,还可以进行日期转换,包括农历和公历的转换。
在Excel中,我们可以使用一些公式来实现农历和公历的转换。
下面将介绍一些常用的Excel公式,帮助大家在农历和公历之间进行转换。
一、农历转公历公式农历转公历是指将农历日期转换为公历日期。
在Excel中,可以使用以下公式来实现农历转公历的计算:```=DATE(YEAR(公历日期), 2, 1) + 农历天数 - 1```其中,公历日期是指要转换的公历日期,农历天数是指要转换的农历日期对应的天数。
通过这个公式,我们可以将农历日期转换为公历日期。
二、公历转农历公式公历转农历是指将公历日期转换为农历日期。
在Excel中,可以使用以下公式来实现公历转农历的计算:```=公历日期 - DATE(YEAR(公历日期), 2, 1) + 1```其中,公历日期是指要转换的公历日期。
通过这个公式,我们可以将公历日期转换为农历日期。
三、应用示例下面通过一个示例来演示如何在Excel中进行农历和公历的转换。
假设我们要将农历2022年正月初一转换为公历日期。
首先,我们需要知道农历2022年正月初一对应的公历日期是什么。
根据农历日历,我们知道2022年的农历正月初一对应的公历日期是2月1日。
接下来,我们可以使用上述的公式来进行转换。
在一个单元格中输入农历日期2022/1/1,然后在另一个单元格中输入以下公式:```=DATE(YEAR(A1), 2, 1) + A1 - 1```其中,A1是指包含农历日期的单元格。
按下回车键后,我们可以在这个单元格中得到公历日期2022/2/1,这就是农历2022年正月初一对应的公历日期。
类似地,如果我们要将公历日期2022/2/1转换为农历日期,我们可以在一个单元格中输入公历日期2022/2/1,然后在另一个单元格中输入以下公式:```=A1 - DATE(YEAR(A1), 2, 1) + 1```按下回车键后,我们可以在这个单元格中得到农历日期2022/1/1,这就是公历2022/2/1对应的农历日期。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
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) = 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) = 1175NongliData(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) = 204070 NongliData(46) = 3477 NongliData(47) = 461653 NongliData(48) = 1386 NongliData(49) = 2413 NongliData(50) = 330077 NongliData(51) = 1197 NongliData(52) = 2637NongliData(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) = 2709 NongliData(90) = 2890 NongliData(91) = 267946 NongliData(92) = 2773 NongliData(93) = 592565 NongliData(94) = 1210 NongliData(95) = 2651 NongliData(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。