-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
49 lines (47 loc) · 1.56 KB
/
Program.cs
File metadata and controls
49 lines (47 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OfficeOpenXml;
internal class Program
{
private static void Main(string[] args)
{
FileInfo fi = new FileInfo("tel.xlsx");
string path = "Contacts.vcf";
using (ExcelPackage excelPackage = new ExcelPackage(fi))
{
if (!fi.Exists)
{
ExcelWorksheet worksheet = excelPackage.Workbook.Worksheets.Add("tel");
excelPackage.SaveAs(fi);
return;
}
ExcelWorksheet sheet = excelPackage.Workbook.Worksheets[0];
int i = 1;
File.WriteAllText(path, "");
while (sheet.Cells[i, 2].Value != null)
{
string tel = sheet.Cells[i, 2].Value.ToString();
switch (tel.First())
{
case '9':
tel = "+7" + tel;
break;
case '8':
tel = "+7" + tel.Remove(0, 1);
break;
case '7':
tel = "+" + tel;
break;
default:
break;
}
File.AppendAllText(path, "BEGIN:VCARD\r\nVERSION:2.1\r\nN:" + sheet.Cells[i, 1].Value.ToString() + ";;;;\r\nFN:" + sheet.Cells[i, 1].Value.ToString() + "\r\nTEL;CELL:" + tel + "\r\nEND:VCARD\r\n\r\n");
i++;
}
}
}
}