所以在此紀錄
格式說明:
1.
整個行事曆以BEGIN:VCALENDAR ….. END:VCALENDAR包起來
2.
檔頭描述:PRODID:-//Taipei
Calendar … VERSION:2.0
3.
單一行程以BEGIN:VEVENT ……END:VEVENT包起來
4.
DTSTAMP:產生時間
5.
SUMMARY;LANGUAGE=zh-tw:行程名稱
6.
PRIORITY:行程重要性,高:1, 一般:5, 低:9
7.
DTSTART:時間開始
8.
DTEND:時間結束
9.
DTSTART;VALUE=DATE:整天
private void ToIcs(DataTable dgv)
{
string TSQL = "BEGIN:VCALENDAR";
TSQL += "\r\n";
TSQL += "PRODID:-//Taipei Calendar";
TSQL += "\r\n";
TSQL += "VERSION:2.0";
TSQL += "\r\n";
for (int row = 0; row < dgv.Rows.Count; row++)
{
TSQL += "BEGIN:VEVENT";
TSQL += "\r\n";
TSQL += "DTSTAMP:" +
DateTime.Now.ToString("yyyyMMdd") + "T" + DateTime.Now.ToString("HHmmss");
TSQL += "\r\n";
//PRIORITY:行程重要性,高:1, 一般:5, 低:9
TSQL += "PRIORITY:" + dgv.Rows[row]["IMPORTANCE"].ToString();
TSQL += "\r\n";
//T後面紀錄的是時分秒
TSQL += "DTSTART:" + dgv.Rows[row]["START_DATE"].ToString() + "T000000";
TSQL += "\r\n";
TSQL += "DTEND:" + dgv.Rows[row]["END_DATE"].ToString() + "T230000";
TSQL += "\r\n";
TSQL += "SUMMARY;LANGUAGE=zh-tw:" + dgv.Rows[row]["TITLE"].ToString() ;
TSQL += "\r\n";
if (dgv.Rows[row]["IS_ALL_DAY"].ToString() == "Y")
{
TSQL += "DTSTART;VALUE=DATE::整天";
TSQL += "\r\n ";
}
TSQL += "DESCRIPTION:" + dgv.Rows[row]["CONTENT"].ToString();
TSQL += "\r\n";
TSQL += "END:VEVENT";
TSQL += "\r\n";
}
TSQL += "END:VCALENDAR";
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.Filter = ".ics |";
saveFileDialog1.Title = "匯出行事曆";
saveFileDialog1.ShowDialog();
if (saveFileDialog1.FileName != "")
{
System.IO.File.WriteAllText(
saveFileDialog1.FileName.Replace(".ics","") + ".ics", TSQL.ToString());
}
}
沒有留言:
張貼留言