diff --git a/Src/MiniExcel.linq b/Src/MiniExcel.linq
index e077c67..a5d0188 100644
--- a/Src/MiniExcel.linq
+++ b/Src/MiniExcel.linq
@@ -11,32 +11,55 @@
System.IO.Compression
System.Net.Http
System.Threading.Tasks
+ System.IO.Packaging
void Main()
+{
+ //Read();
+ Create();
+}
+
+void Read()
+{
+ //
+ {
+ // idea from : [Reading and Writing to Excel 2007 or Excel 2010 from C# - Part II: Basics | Robert MacLean](https://www.sadev.co.za/content/reading-and-writing-excel-2007-or-excel-2010-c-part-ii-basics)
+ Package xlsxPackage = Package.Open(@"D:\git\MiniExcel\Samples\Xlsx\OpenXmlSDK_InsertCellValues\OpenXmlSDK_InsertCellValues.xlsx", FileMode.Open, FileAccess.ReadWrite);
+ var allParts = xlsxPackage.GetParts().ToList();
+ PackagePart worksheetPart = (from part in allParts
+ where part.ContentType.Equals("application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml")
+ select part).FirstOrDefault();
+ XElement worksheet = XElement.Load(XmlReader.Create(worksheetPart.GetStream()));
+
+ }
+}
+
+void Create()
{
var path = Path.Combine(Path.GetTempPath(), $"{Guid.NewGuid()}.xlsx");
Console.WriteLine(path);
- MiniExcelHelper.CreateEmptyFie(path);
+ //MiniExcelHelper.CreateEmptyFie(path);
//MiniExcelHelper.Create(path, new[] {1,2,3,4,5});
- //MiniExcelHelper.Create(path, new[] { new { x = "<", y = 12}, new { x = ">", y = 22} });
- //MiniExcelHelper.Create(path, new[] {
- // new { a = "Hello World", b = 1234567890,c = true,d=DateTime.Now },
- // new { a = "", b = -1234567890,c=false,d=DateTime.Now.Date}
- //});
+ MiniExcelHelper.Create(path, new[] {
+ new { a = @"""<>+-*//}{\\n", b = 1234567890,c = true,d=DateTime.Now },
+ new { a = "Hello World", b = -1234567890,c=false,d=DateTime.Now.Date}
+ });
// TODO: Dapper Row
// TODO: Dictionary
// TODO: Datatable
- ProcessStartInfo psi = new ProcessStartInfo
- {
- FileName = path,
- UseShellExecute = true
- };
- Process.Start(psi);
+
+
+ //ProcessStartInfo psi = new ProcessStartInfo
+ //{
+ // FileName = path,
+ // UseShellExecute = true
+ //};
+ //Process.Start(psi);
}
namespace MiniExcel
@@ -47,18 +70,18 @@ namespace MiniExcel
using System.Text;
using MiniExcel;
- public class MiniExcelHelper
+ public static class MiniExcelHelper
{
public static Dictionary GetDefaultFilesTree()
{
return new Dictionary()
{
- {"[Content_Types].xml",defaultContent_TypesXml},
- {@"_rels\.rels",defaultRels},
- {@"xl\_rels\workbook.xml.rels",defaultWorkbookXmlRels},
- {@"xl\styles.xml",defaultStylesXml},
- {@"xl\workbook.xml",defaultWorkbookXml},
- {@"xl\worksheets\sheet1.xml",defaultSheetXml},
+ {"[Content_Types].xml",DefualtXml.defaultContent_TypesXml},
+ {@"_rels\.rels",DefualtXml.defaultRels},
+ {@"xl\_rels\workbook.xml.rels",DefualtXml.defaultWorkbookXmlRels},
+ {@"xl\styles.xml",DefualtXml.defaultStylesXml},
+ {@"xl\workbook.xml",DefualtXml.defaultWorkbookXml},
+ {@"xl\worksheets\sheet1.xml",DefualtXml.defaultSheetXml},
};
}
@@ -92,7 +115,7 @@ namespace MiniExcel
foreach (var p in props)
{
var columname = Helper.ConvertXyToCell(xIndex, yIndex);
- sb.Append($"");
+ sb.Append($"");
sb.Append($"{p.Name}");
sb.Append($"");
sb.Append($"");
@@ -179,23 +202,25 @@ namespace MiniExcel
}
}
- private const string defaultRels = @"
+ internal static class DefualtXml
+ {
+ internal const string defaultRels = @"
";
- private const string defaultSheetXml = @"
+ internal const string defaultSheetXml = @"
";
- private const string defaultWorkbookXmlRels = @"
+ internal const string defaultWorkbookXmlRels = @"
";
- private const string defaultStylesXml = @"
+ internal const string defaultStylesXml = @"
@@ -215,7 +240,7 @@ namespace MiniExcel
";
- private const string defaultWorkbookXml = @"
+ internal const string defaultWorkbookXml = @"
@@ -223,28 +248,27 @@ namespace MiniExcel
";
- private const string defaultContent_TypesXml = @"
+ internal const string defaultContent_TypesXml = @"
";
+ }
-
-
- private static class Helper
+ internal static class Helper
{
- public static string GetValue(object value) => value == null ? "" : value.ToString().Replace("<", "<").Replace(">", ">");
+ internal static string GetValue(object value) => value == null ? "" : value.ToString().Replace("<", "<").Replace(">", ">");
/// X=CellLetter,Y=CellNumber,ex:A1=(1,1),B2=(2,2)
- public static string ConvertXyToCell(Tuple xy)
+ internal static string ConvertXyToCell(Tuple xy)
{
return ConvertXyToCell(xy.Item1, xy.Item2);
}
/// X=CellLetter,Y=CellNumber,ex:A1=(1,1),B2=(2,2)
- public static string ConvertXyToCell(int x, int y)
+ internal static string ConvertXyToCell(int x, int y)
{
int dividend = x;
string columnName = String.Empty;
@@ -260,7 +284,7 @@ namespace MiniExcel
}
/// X=CellLetter,Y=CellNumber,ex:A1=(1,1),B2=(2,2)
- public static Tuple ConvertCellToXY(string cell)
+ internal static Tuple ConvertCellToXY(string cell)
{
const string keys = " ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const int mode = 26;
@@ -275,7 +299,7 @@ namespace MiniExcel
return Tuple.Create(x, int.Parse(cellNumber));
}
- public static string GetCellNumber(string cell)
+ internal static string GetCellNumber(string cell)
{
string cellNumber = string.Empty;
for (int i = 0; i < cell.Length; i++)
@@ -286,7 +310,7 @@ namespace MiniExcel
return cellNumber;
}
- public static string GetCellLetter(string cell)
+ internal static string GetCellLetter(string cell)
{
string GetCellLetter = string.Empty;
for (int i = 0; i < cell.Length; i++)