背景:
由於在職研究生和日常工作內容都具有不定時性,為方便工作、學習,擬使用多終端的軟件來記錄接下來若干天的工作學習內容。
初步計划將值班表、課表導入到支持多終端平台的日歷程序中。
初步設想:
研究發現,值班表、課表都是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同理。