forked from XINCGer/UnityToolchainsTrick
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExample_14_ExcelShareRead.cs
53 lines (49 loc) · 1.85 KB
/
Example_14_ExcelShareRead.cs
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
50
51
52
53
using System.Collections;
using System.Collections.Generic;
using System.IO;
using OfficeOpenXml;
using UnityEditor;
using UnityEngine;
namespace ToolKits
{
public class Example_14_ExcelShareRead
{
private const string PATH = "Excels/Example.xlsx";
[MenuItem("Tools/Excel/NormalRead",priority = 14)]
private static void NormalRead()
{
using (ExcelPackage excelPackage = new ExcelPackage(new FileStream(PATH,FileMode.Open,FileAccess.Read,FileShare.Read)))
{
var workbook = excelPackage.Workbook.Worksheets[1];
for (int i = 1; i <= workbook.Dimension.End.Row; i++)
{
var key = workbook.GetValue(i, 1);
Debug.Log($"Key: {key}");
for (int j = 2; j <= workbook.Dimension.End.Column; j++)
{
var value = workbook.GetValue(i, j) as string;
Debug.Log($"value{j} : {value}");
}
}
}
}
[MenuItem("Tools/Excel/ShareRead",priority = 14)]
private static void ShareRead()
{
using (ExcelPackage excelPackage = new ExcelPackage(new FileStream(PATH,FileMode.Open,FileAccess.Read,FileShare.ReadWrite)))
{
var workbook = excelPackage.Workbook.Worksheets[1];
for (int i = 1; i <= workbook.Dimension.End.Row; i++)
{
var key = workbook.GetValue(i, 1);
Debug.Log($"Key: {key}");
for (int j = 2; j <= workbook.Dimension.End.Column; j++)
{
var value = workbook.GetValue(i, j) as string;
Debug.Log($"value{j} : {value}");
}
}
}
}
}
}