Skip to content

Commit 1ed731e

Browse files
committed
Working on sample 30-Working with range. Merged FileUtils to one class
1 parent d931fc2 commit 1ed731e

File tree

39 files changed

+317
-208
lines changed

39 files changed

+317
-208
lines changed

01-GettingStarted/GettingStartedSample.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public static string Run()
110110
package.Workbook.Properties.SetCustomPropertyValue("Checked by", "Jan Källman");
111111
package.Workbook.Properties.SetCustomPropertyValue("AssemblyName", "EPPlus");
112112

113-
var xlFile = FileOutputUtil.GetFileInfo("01-GettingStarted.xlsx");
113+
var xlFile = FileUtil.GetCleanFileInfo("01-GettingStarted.xlsx");
114114

115115
// Save our new workbook in the output directory and we are done!
116116
package.SaveAs(xlFile);

02-ReadWorkbook/ReadWorkbookSample.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class ReadWorkbookSample
2323
{
2424
public static void Run()
2525
{
26-
var filePath = FileInputUtil.GetFileInfo("02-ReadWorkbook", "ReadWorkbook.xlsx").FullName;
26+
var filePath = FileUtil.GetFileInfo("02-ReadWorkbook", "ReadWorkbook.xlsx").FullName;
2727
Console.WriteLine("Reading column 2 of {0}", filePath);
2828
Console.WriteLine();
2929

03-UsingAsyncAwait/UsingAsyncAwaitSample.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class UsingAsyncAwaitSample
3030
/// <param name="connectionString">The connection string to the SQLite database</param>
3131
public static async Task RunAsync(string connectionString)
3232
{
33-
var file = FileOutputUtil.GetFileInfo("03-AsyncAwait.xlsx");
33+
var file = FileUtil.GetCleanFileInfo("03-AsyncAwait.xlsx");
3434
using (ExcelPackage package = new ExcelPackage(file))
3535
{
3636
var ws = package.Workbook.Worksheets.Add("Sheet1");
@@ -54,10 +54,10 @@ public static async Task RunAsync(string connectionString)
5454
await package.LoadAsync(file);
5555

5656
var newWs = package.Workbook.Worksheets.Add("AddedSheet2");
57-
var range = await newWs.Cells["A1"].LoadFromTextAsync(FileInputUtil.GetFileInfo("03-UsingAsyncAwait", "Importfile.txt"), new ExcelTextFormat { Delimiter='\t' });
57+
var range = await newWs.Cells["A1"].LoadFromTextAsync(FileUtil.GetFileInfo("03-UsingAsyncAwait", "Importfile.txt"), new ExcelTextFormat { Delimiter='\t' });
5858
range.AutoFitColumns();
5959

60-
await package.SaveAsAsync(FileOutputUtil.GetFileInfo("03-AsyncAwait-LoadedAndModified.xlsx"));
60+
await package.SaveAsAsync(FileUtil.GetCleanFileInfo("03-AsyncAwait-LoadedAndModified.xlsx"));
6161
}
6262
}
6363
}

04-LoadingData/LoadingDataFromCollectionWithAttributes.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public static void Run()
5959
new Actor2{ Salary = 315.34, Tax = 0.28, FirstName = "Lisa", MiddleName = "Maria", LastName = "Gonzales", Birthdate = new DateTime(1971, 10, 2)}
6060
};
6161

62-
using (var package = new ExcelPackage(FileOutputUtil.GetFileInfo("04-LoadFromCollectionAttributes.xlsx")))
62+
using (var package = new ExcelPackage(FileUtil.GetCleanFileInfo("04-LoadFromCollectionAttributes.xlsx")))
6363
{
6464
// using the Actor class above
6565
var sheet = package.Workbook.Worksheets.Add("Actors");

04-LoadingData/LoadingDataWithDynamicObjects.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public static void Run()
5252
};
5353

5454
// Create a workbook with a worksheet and load the data into a table
55-
using(var package = new ExcelPackage(FileOutputUtil.GetFileInfo("04-LoadDynamicObjects.xlsx")))
55+
using(var package = new ExcelPackage(FileUtil.GetCleanFileInfo("04-LoadDynamicObjects.xlsx")))
5656
{
5757
var sheet = package.Workbook.Worksheets.Add("Dynamic");
5858
sheet.Cells["A1"].LoadFromDictionaries(items, c =>
@@ -69,8 +69,8 @@ public static void Run()
6969
}
7070

7171
// Load data from json (in this case a file)
72-
var jsonItems = JsonConvert.DeserializeObject<IEnumerable<ExpandoObject>>(File.ReadAllText(FileInputUtil.GetFileInfo("04-LoadingData", "testdata.json").FullName));
73-
using (var package = new ExcelPackage(FileOutputUtil.GetFileInfo("04-LoadJsonFromFile.xlsx")))
72+
var jsonItems = JsonConvert.DeserializeObject<IEnumerable<ExpandoObject>>(File.ReadAllText(FileUtil.GetFileInfo("04-LoadingData", "testdata.json").FullName));
73+
using (var package = new ExcelPackage(FileUtil.GetCleanFileInfo("04-LoadJsonFromFile.xlsx")))
7474
{
7575
var sheet = package.Workbook.Worksheets.Add("Dynamic");
7676
sheet.Cells["A1"].LoadFromDictionaries(jsonItems, c =>

04-LoadingData/LoadingDataWithTablesSample.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public static void Run()
3333
var pck = new ExcelPackage();
3434

3535
//Create a datatable with the directories and files from the current directory...
36-
DataTable dt = GetDataTable(FileOutputUtil.GetDirectoryInfo("."));
36+
DataTable dt = GetDataTable(FileUtil.GetDirectoryInfo("."));
3737

3838
var wsDt = pck.Workbook.Worksheets.Add("FromDataTable");
3939

@@ -108,7 +108,7 @@ orderby file.Name ascending
108108
wsList.Cells[wsList.Dimension.Address].AutoFitColumns();
109109

110110
//...and save
111-
var fi = FileOutputUtil.GetFileInfo("04-LoadingData.xlsx");
111+
var fi = FileUtil.GetCleanFileInfo("04-LoadingData.xlsx");
112112
pck.SaveAs(fi);
113113
pck.Dispose();
114114
}

05-ImportAndExportCsvFiles/ImportAndExportCsvFilesSample.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public static class ImportAndExportCsvFilesSample
3737
/// <returns></returns>
3838
public static async Task<string> Run()
3939
{
40-
FileInfo newFile = FileOutputUtil.GetFileInfo(@"05-LoadDataFromCsvFilesIntoTables.xlsx");
40+
FileInfo newFile = FileUtil.GetCleanFileInfo(@"05-LoadDataFromCsvFilesIntoTables.xlsx");
4141

4242
using (ExcelPackage package = new ExcelPackage())
4343
{
@@ -60,7 +60,7 @@ private static async Task ExportTableAsync(ExcelPackage package)
6060
Encoding = new UTF8Encoding(),
6161
SkipLinesEnd=1 //Skip the totals row
6262
};
63-
await ws.Cells[tbl.Address.Address].SaveToTextAsync(FileOutputUtil.GetFileInfo("05-ExportedFromEPPlus.csv"), format);
63+
await ws.Cells[tbl.Address.Address].SaveToTextAsync(FileUtil.GetCleanFileInfo("05-ExportedFromEPPlus.csv"), format);
6464

6565
Console.WriteLine($"Writing the text file 'ExportedTable.csv'...");
6666
}
@@ -79,7 +79,7 @@ private static void LoadFile1(ExcelPackage package)
7979
SkipLinesEnd = 1
8080
};
8181

82-
var file1 = FileInputUtil.GetFileInfo("05-ImportAndExportCsvFiles", "Sample5-1.txt");
82+
var file1 = FileUtil.GetFileInfo("05-ImportAndExportCsvFiles", "Sample5-1.txt");
8383

8484
//Now read the file into the sheet. Start from cell A1. Create a table with style 27. First row contains the header.
8585
Console.WriteLine("Load the text file...");
@@ -150,7 +150,7 @@ private static async Task LoadFile2Async(ExcelPackage package)
150150

151151
//Now read the file into the sheet.
152152
Console.WriteLine("Load the text file...");
153-
var file2 = FileInputUtil.GetFileInfo("05-ImportAndExportCsvFiles", "Sample5-2.txt");
153+
var file2 = FileUtil.GetFileInfo("05-ImportAndExportCsvFiles", "Sample5-2.txt");
154154

155155
var range = await sheet.Cells["A1"].LoadFromTextAsync(file2, format);
156156

06-FormulaCalculation/CalculateExistingWorkbook.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ private static void RemoveCalculatedFormulaValues(ExcelWorkbook workbook)
5252
public void Run()
5353
{
5454
//var resourceStream = GetResource("EPPlusSampleApp.Core.FormulaCalculation.FormulaCalcSample.xlsx");
55-
var filePath = FileInputUtil.GetFileInfo("06-FormulaCalculation", "FormulaCalcSample.xlsx").FullName;
55+
var filePath = FileUtil.GetFileInfo("06-FormulaCalculation", "FormulaCalcSample.xlsx").FullName;
5656
using (var package = new ExcelPackage(new FileInfo(filePath)))
5757
{
5858
// Read the value from the workbook. This is calculated by Excel.

07-OpenWorkbookAddDataAndChart/OpenWorkbookAndAddDataAndChart.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ public class OpenWorkbookAndAddDataAndChartSample
2929
/// </summary>
3030
public static string Run()
3131
{
32-
FileInfo newFile = FileOutputUtil.GetFileInfo("07-OpenWorkbookAndAddDataAndChartSample.xlsx");
33-
FileInfo templateFile = FileInputUtil.GetFileInfo("07-OpenWorkbookAddDataAndChart", "ExistingWorkbook.xlsx");
32+
FileInfo newFile = FileUtil.GetCleanFileInfo("07-OpenWorkbookAndAddDataAndChartSample.xlsx");
33+
FileInfo templateFile = FileUtil.GetFileInfo("07-OpenWorkbookAddDataAndChart", "ExistingWorkbook.xlsx");
3434

3535
using (ExcelPackage package = new ExcelPackage(newFile, templateFile))
3636
{

08-SalesReport/SalesReport.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class SalesReportFromDatabase
2929
/// <param name="connectionString">The connection string to the SQLite database</param>
3030
public static string Run(string connectionString)
3131
{
32-
var file = FileOutputUtil.GetFileInfo("08-Salesreport.xlsx");
32+
var file = FileUtil.GetCleanFileInfo("08-Salesreport.xlsx");
3333
using (ExcelPackage xlPackage = new ExcelPackage(file))
3434
{
3535
ExcelWorksheet worksheet = xlPackage.Workbook.Worksheets.Add("Sales");

0 commit comments

Comments
 (0)