背景:
由于在职研究生和日常工作内容都具有不定时性,为方便工作、学习,拟使用多终端的软件来记录接下来若干天的工作学习内容。
初步计划将值班表、课表导入到支持多终端平台的日历程序中。
初步设想:
研究发现,值班表、课表都是xls格式,可以用宏轻松生成辨识度较高的txt或csv。ics格式太过复杂,不考虑直接生成。目前国内没有支持多终端云同步的日历程序。国外google日历、outlook日历、ios自带日历均支持多终端云同步。但后两者只支持导入ics文件,google日历支持导入csv,且支持导出ics。但google日历因为国情原因,连接不是很靠谱。
故决定,宏生成csv->导入到google日历->google日历导出ics->导入到outlook,手机和pc都有outlook,后续多终端均可查看。
实现步骤:
1.值班表由于涉密,不做展示。课表宏如下,生成后将其拷贝到单独的csv,保存。

Sub 生成计划() Dim i, j, x, y, t, a, mid_line As Integer Dim date_val, date_val_2w_ago, date_val_3w_ago As Date Dim start_time, end_time, date_str As String Dim s As Range For Each s In ActiveSheet.UsedRange.Cells If s.MergeCells Then s.Select s.UnMerge Selection.Value = s.Value End If Next s '周次开始的行数 x = 5 '“上午、下午、晚上”所在的行 mid_line = 4 a = 0 With ActiveSheet a = a + 1 t = 1 .Cells(a, 24 + t).Value = "Subject" t = t + 1 .Cells(a, 24 + t).Value = "Start Date" t = t + 1 .Cells(a, 24 + t).Value = "Start Time" t = t + 1 .Cells(a, 24 + t).Value = "End Date" t = t + 1 .Cells(a, 24 + t).Value = "End Time" t = t + 1 .Cells(a, 24 + t).Value = "All Day Event" t = t + 1 .Cells(a, 24 + t).Value = "Description" t = t + 1 .Cells(a, 24 + t).Value = "Location" t = t + 1 .Cells(a, 24 + t).Value = "Private" For i = x To .UsedRange.Rows.Count For j = 3 To 10 If InStr(.Cells(i, j).Value, "放假") <= 0 And InStr(.Cells(i, j).Value, "工作日") <= 0 And .Cells(i, j).Value <> "" And WorksheetFunction.IsNumber(.Cells(i, 1).Value) Then Select Case .Cells(mid_line, j).Value Case "上午" start_time = "9:00 AM" end_time = "12:20 PM" Case "下午" start_time = "2:00 PM" end_time = "5:20 PM" Case "晚上" start_time = "6:30 PM" end_time = "9:50 PM" End Select Select Case .Cells(mid_line - 1, j).Value Case "星期六" date_str = Mid(.Cells(i, 2).Value, 1, InStr(.Cells(i, 2).Value, "-") - 1) Case "星期日" date_str = Right(.Cells(i, 2).Value, InStr(.Cells(i, 2).Value, "-") - 1) End Select a = a + 1 t = 1 .Cells(a, 24 + t).Value = .Cells(i, j).Value t = t + 1 .Cells(a, 24 + t).Value = Format(date_str, "mm/dd/yyyy") t = t + 1 .Cells(a, 24 + t).Value = start_time t = t + 1 .Cells(a, 24 + t).Value = Format(date_str, "mm/dd/yyyy") t = t + 1 .Cells(a, 24 + t).Value = end_time t = t + 1 .Cells(a, 24 + t).Value = "FALSE" t = t + 1 .Cells(a, 24 + t).Value = .Cells(i, j).Value t = t + 1 .Cells(a, 24 + t).Value = "12-110" t = t + 1 .Cells(a, 24 + t).Value = "False" End If Next Next End With End Sub
2.打开https://calendar.google.com/calendar,点击【设置-日历-导入日历-选择csv成功导入】,再点击【设置-日历-导出日历】,即可导出ics文件。
3.打开https://outlook.live.com,登录hotmail邮箱。左上角选择“日历”,再点击【添加日历-从文件】导入ics文件。
4.手机基于exchange设置邮箱,即可读取日历。pc同理。