Creating Excel Files in C#

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
one of the most important tools in business is excel spreadsheets are an easy way to visualize and manipulate data that almost any user can operate so it makes sense that you would benefit from outputting your data to excel in fact you can even use excel as your default reporting tool in this video i'm going to show you how to output data to excel how to format the document and then also how to read that data back into c sharp from excel now this is your first video you've watched of mine my name is tim corey and it's my goal to make learning c-sharp easier i provide videos twice a week here on youtube to help you grow as a developer i also have a full set of training courses on iamtimcory.com i encourage you to check out all the resources that i have to offer now in this video as with most videos i'm going to create some source code if you'd like a copy of my source code you can use the link in the description to get it so let's get started in visual studio 2019 now in this project i'm going to use a console application but this is just because the console is the very cleanest user interface there is there's not a lot of overhead and a lot of things like buttons and other stuff to worry about layouts that kind of stuff the console is really clean and simple but you can use this code in any user interface practically the one exception will probably be the blazer web assembly which is a different animal that works all client-side so you probably have to generate your excel file in the api portion of it and then download it to blaze webassembly but otherwise pretty much anything will work as far as hosting this as a user interface so let's choose the consoleapp.net core and we're going to say that this console app let's give it a name just call it excel demo and we'll call it excel demo app for our solution name and hit create now by default this is going to create a net core 3.1 application but the very first thing i'm going to do is i'm going to get the latest and greatest version which i'm going to right click and go to properties and change this to net core 5.0 the code will be exactly the same as far as excel goes but i do want to have some of the benefits of c sharp 9 and the latest code available to me now once we're in our application we can get rid of the hello world and now let's right click on dependencies and go to manage nuget packages we're going to bring in just one nuget package today and that is a package called ep plus so two-piece now this is a is not a free software if you're using it for commercial use if you use it for non-commercial or open source work it's totally free but if using it for commercial purposes then there is a licensing fee i believe it's 300 an application something like that um but if you're using it for commercial purposes you should be paying for it so that's what they have required and i definitely support their desire to to eat so let's hit install and this is a great package there are other packages out there that do some of the similar things i have found this is the most comprehensive and the most polished uh package out here and actually highlighted in my 10 packages to look for in 2021 so we're gonna go over how to use the basics of ep plus now right away they get they open up the readme.txt which is really helpful because it talks about their licenses how to get a license if you're not using it for commercial purposes how do you work with this in fact this right here is what you need to do if you're going to use it for a non-commercial project now this is the honor system so that you could in fact use this illegally by using this and saying it's non-commercial but use it for commercial application don't do that okay respect people's um wishes when it comes to open source code all right so i'm going to copy this non-commercial license here this is a non-commercial use and then let's just paste that right there and it's going to ask for control control dot here and let's say using office open xml and there we go so now we have our license in place to use our excel manipulation project next up let's create a file location for our excel file so let's say var file equals new file info which is going to system.io notice who's going to add that using statement so dot oops not dot open paren and we'll give it a path let's give this path we're gonna hard code this just you know i'm putting the the at symbol in front so i can use a single slash instead of double slash we're gonna hard code this path just because it makes it easier a lot of this i'm doing here is to show you just the excel file manipulation i'm doing it right in the console i'm not doing it in a class library i'm not using app settings for the file name and so on this is in order to give you a very clean demo if i were going to use its production i put this in a class library i would probably abstract away a lot of the work and create something custom just for my application for saving and loading excel files but again this is a demo i'm going to tell you about the best practices i'm going to mention them so that you're aware i don't want to falsely represent how you do these things but at the same time i want to keep this as simple as possible in my code so you're not confused by seeing things that don't necessarily apply to your situation okay so let's hard code this to c colon slash demos slash let's call this youtube youtubedemo.xlsx okay so that's our our file path for our new file now let's open up that location um there you go and there's nothing in there okay there's no there's no file there right now just so you know it does not exist yet the path does but the the file itself does not and that's important because we're going to create that file now we're going to start with saving to an excel file since we don't have an excel file yet we're going to save to one but in order to do that we have to have data and typically in c sharp the way data is represented is with a list of objects so let's create a class for our data i'm going to do it right here i'm going to say public class person model and create let's create three properties an id a first name and a last name all right very simple class um that just gives us three properties to to play around with now i've created i like to create these classes right in line with my current class i can see them and maybe if i have data up here i can mirror that or represent that well but then i'm done if you control dot on the class itself you can say move type to personmodel.cs and that creates a separate file for person model so there you go so it's a quick way of doing that makes it really convenient for creation and then also for doing it right later so now i have my person model i'm going to do it's going to create a helper method so let's call this static list of person model i'll call it get setup data all right now i call this static because the fact that we're inside of class program and so static void main in order for this to call other methods inside this same class i have to use the word static because i'm not instantiating this class so that's just a a reference to the fact that i have to um call from this method right here i have to call this method directly instead of instantiating a new class i could create a separate class and do those all a separate class and instantiate that i'm not going to go that far again we're trying to keep it simple for the demo so list of person model and we'll call it output equals new i'm using the new syntax with c-sharp nine this is why i move to net five which i can just say just new open close parentheses i don't have to say new list of person model and duplicate that next up i have my curly braces let's say new and again just say new because it knows oh it's a person model and then we'll say id equals one uh first name equals not japanese calendar whoops um tim wow there's tim i do know my first name last name equals corey okay and then we'll do is we'll uh put a comma at the end of that and then copy that line a couple times let's do let's just do two more so two and three sue storm and jane smith there we go so and we'll take that last comma off we can leave it if we wanted to but i'm going to take it off so now we have his output list which is a new list of person which has three new person models in it with the data that you see and we'll just return that cool so now we have our our setup data this is the data we're gonna store in excel so this is represents data that might come from a database or a day that you create from the front end or however you get this data this is what you want to output to excel so let's start with this format okay so now up in our main method we're going to say var people equals get setup data and that will just load in that list of person model i could have done it right in line but this way it makes my code a little cleaner in my main method my main method is essentially going to be the quarterback method the method that calls every other method to do work and passes those things around that's kind of what i'm i'm going for here so now let's create a method and we're going to call it here i'll call it first just because it's um where i kind of define what that method should look like but one of the things that we're going to do in this call we're going to save data to excel and that's something that should probably done asynchronously because of the fact that it may take a little bit if you have a large amount of data you're saving to excel you don't want the application to lock up and appear as though it's not functional so we're going to do is we're doing a wait here which means we have to change our static void main to static async task and control dot to add that using and this is just fine this is something that came in like oh goodness maybe c sharp seven somewhere around there um that this came in to allow us to change our static void means to be static async task main so we can call asynchronous methods right inside of our main method without any kind of weird manipulation we used to have to do so that does work it is legal and allowed and it's preferred to do this if you're on call asynchronous methods so now we can say await let's call it a save excel file i know this has not been created yet we will create it and we'll say let's pass in people and the file so we're gonna pass in the the list of people we just created and also the file we're gonna write to and let's just do a control dot here to generate that method so that generates this method down here which sets everything up for us which is kind of nice is you know private static task save excel file passing the list of person model called people and the file info called file that all works for me so i think we can leave that as such just get rid of the throw notice here that i didn't use private but this one does use private we can do private hearing probably should if you don't put private it's assumed to be private so that just saying static is just the same as saying private static but this way by saying it explicitly you're ensuring that everyone knows that it's private okay so that's kind of the difference there okay so in our our save file the first thing i want to do it's going to yellow saying hey you don't have um a return here no worries we'll get there the first thing i want to do is actually create another method and that method i'm going to say let's say delete if exists and pass in the file what this is going to do is check to see those file exists if it does delete it before you run this application this is a demo application and so we're going to run this a lot of times possibly and if you do you have to make sure you delete the file every time otherwise i yell at you well this way it deletes it for us so let's do control dot to generate that method and then in here it's a really simple method where i say if file dot exists then file dot delete oops that's a method that's it so if exists delete it i could have done as a one-liner here probably but let's just create a method for that just to be very clear on what it does so now for our demo purposes this cleans things up as we get started to make sure that the um system does not throw an error or exception if we already have a file there okay now on to the actually working with excel part that you've been looking forward to using now if you don't know what a using statement is what this is is it whatever you instantiate in here in fact we'll let's do the instantiation uh var let's call it package be explicit equals new excel package and we're going to base it upon that file name so we're instantiating this package variable and because we're doing it inside of a using statement what happens is as soon as we get to this last curly brace down here this package will be disposed of properly this package has on it let's just show you package dot dispose there's this method called dispose and this method is supposed to be called at the end whenever you're done to clean up the package to make sure there's no resources that are outstanding or hanging out there for example we're working with an excel file so it it's going to leave that file open while we manipulate it well we want to close it so that somebody else could open it it doesn't have a a right lock on it because the fact is open somewhere else so it's very important we call this dispose method but we often forget to do that or you might have an exception that causes a problem that doesn't get this line well that's where the using statement comes into play because the using statement says anything in here that gets instantiated inside is these parentheses anything inside there needs to be needs to have implemented the i disposable interface and so that i disposable has one method called dispose so since it implements eye disposable what's going to happen is at the end of this curly brace it's going to call the disposed method for us automatically no matter what successor failure doesn't matter it's calling that disposed method so that's a a safety valve for us is to have this using here so just know that's what using four is for in this context we have our usings up here those are different these are just shortcuts that means we have to type system.io before we type out file so that's just a shortcut down here this is a safety mechanism for us so sorry a little bit of a side track there but it's important to understand why you're doing things uh and just you know in c sharp eight i believe it is we can now use using statements without the curly braces if we wanted to um we're not gonna do that now there's a reason to um but but we could do that if we want to just put a cycle at the end here and now get rid of that and get rid of the curly braces and the var as well oops not the var there we go that would be the same equivalent um and since i've already done it i'll probably leave it like this but what this does is it's the same as the curly braces only it uses the end clear brace for the method to be the the closure to trigger that dispose that can be slightly different if you have um a shorter span inside your code for those curly braces so just know that there can be a little bit of a difference in how you use this but this allows you not to nest as deeply so in case you had two using statements that were nested inside each other you could just have them below each other and not have three or four or five layers deep of curly braces just note that's what that's for okay we're using the user theorem so now i can say var let's do just ws for worksheet keep it uh short equals dot package.workbook.worksheet dot add let's call this main report now what am i doing here well we've already opened the excel package and the excel package is is the file excel file and what is that file well it's it's this file right here youtubedemo.xlsx so we've said open create that file we're open if it's already there but create that file and now we're going to do is we're going to add a worksheet to that file now since i deleted it first that kind of saved us because this is this is just um a hard code main report sheet name if this changed all the time it wouldn't be a problem but if the file exists this works just fine it's gonna open the file up as if we're going to add things to it but you can't add an extra sheet that already's name the same thing as a sheet that's already there okay so that's where you get the except the exception if you didn't delete that file just so you know so normally in excel if you create a new excel document in fact let's just open up excel real quick um and in here you'll notice that it says sheet 1 at the bottom if i add another one that says sheet sheet2 and sheet3 and you can put different things on different documents like so okay but it just named sheet1 well you can rename that if you want so i could say test and now it's the test sheet all right well that's what we're doing in our don't say that um that's what we're doing in right here we're saying hey go ahead and add a sheet called main report so this can be a little bit nicer than even a default for excel where the default is sheet1 well we're going to say main report instead so now we have a new sheet in our new excel file called main report and now we're going to do is we're going to add some some data to it so since i have this list of people i am going to say var range which represents a range of cells let's say range cells equals worksheet dot cells and that starts at a1 oops in quotes a1 that's the that's the start of our range i'm going to say load from collection this allows us to pass in i innumerable of t which we have that's our people if you're wondering well you said well tim actually it's a list of t yes because i in numerable is an interface and list implements the i enumerable interface so we can use that interchangeably there so we have passed in our people list and the last thing i want to do is say true for print headers this is where those those nice little tags help me out here that show me even after i say true it says oh print headers is true which what it's going to do is take our data from our list of people and it's going to save it into excel as columns and rows and the first row is going to be the header row where it takes the property names and it puts them in as the in the first column so that's pretty much it okay so now i'm going to say range dot autofit columns so if we you know in excel sometimes you can have a column is too narrow for your content it kind of um it doesn't show everything and you can double click on the the columns uh the separator bar and expand it out to fit the column well that's kind of we're doing here we're saying hey fiddle us in so that it looks right and we're not having hidden content on our excel file and finally we say await package dot save async there we go save async ah we have one issue left to take care of it doesn't put async in our our method signature when we create that or generate that and i often miss that because it does have task but the reason why is because we don't always have to do a weight in this method we could say not to await this and have no weight instead have it return that back to here to be weighted but in this case we're just going to await it right here that's fine so that's it we have created excel file we have created a new worksheet we have said starting at cell a1 which is the upper left-hand corner of cell load from collection that people which has remember three people in it uh tim sue and jane where i'll load this list into our file so that that's going to go into our file and we're going to print the headers as well we'll auto fit those columns so we can make sure those column widths to the right widths and the height so that the rows are the right heights and then we're going to save asynchronously that excel file that's it we're done that's all it took to write a list of people out to excel okay now don't leave the video yet because we're gonna do a lot more than this but i wanna show you just how simple it is to write to excel so let's pull up that folder we'll wait for it as soon as this runs boop it's done um so it just exited that's all it was let's open this up there we go um i can zoom in a little bit for you we have our id first name and last name one two and three tim sue jane and so on and notice the sheet down here says main report so that's all it took to read or i'm sorry write to excel really straightforward for collections which is the most traditional way of storing data in c sharp anyway so we already have our data in a collection therefore to write it to excel really simple to do boom there you go but that right there is quite plain so if i were doing this i would probably do something like this or i'd bold these i'd probably center this column in fact i'd probably center both of these columns for the headers but leave the bodies left aligned but center this one gives us a number you know i'd probably make maybe one of these a little bigger because you know last names might be a little bit larger sometimes and so on i'd probably play around this and make it a little nicer right well we can do all of that in c sharp so let's do this let's don't save and in fact we're going to delete this let's start over so i know i delete if if exist but i want to show you that yes we are in fact um not there's no trickery here i'm doing it all through code so let's come down here after we autofit our columns and we're going to do some manipulation and in fact i'm going to change this right here to say instead of a1 let's say a2 which means that the header row will start on the second row not the first row because i want to play around that first row and have kind of a report header type feel so down here i'm going to say worksheet dot cells and let's address cell a1 which is no longer the header row that's a2 so dot value equals our cool report so this is kind of the overall title of our report then we have our our column headers after that but the problem is that goes into a1 and and that would be a problem because it's only gonna be over the id column not over first name and last name so let's do this let's um let's say ws cells and let's say that we want a1 colon c1 so a1 through c1 which is the three columns we have for our three our id first name and last name we're gonna say merge and we'll say true that's gonna merge all three of those together so that a1 now spans those three columns but we're not quite done yet i want to say worksheet.cells and i'll do the same thing here let's do actually not in cell let's do columns uh let's do column and say that column one is base one here so column one dot style dot horizontal alignment equals center okay now let's open office xml dot style dot we can get rid of that and do control dot this is a new so you can you know find your your list here like center continuous distributed fill left justify right and so on i'm gonna center column one which just happens to be what our cool report is but also happens to be what the id column is now i could have said hey just just send it to certain cells but i do the whole column because it's convenient for what i want to do now let's also make that first row so ws row and row one which is that our cool report row let's change the style dots font dot size to be 24. it's a really big bold title right and then also on row one so ws.row1 we're going to say that the style is going to be i'm sorry the style dot font we're going to have a color for that and say set color not set auto set color set the color and let's choose a color here so again we have let's not set one of those colors let's just do a color dots whoops capital c dot blue and this uses the system colors here so we can use system.drawing so now you set the the font for our cool report to blue is this getting hideous yeah probably but i just want to show you all the different ways of manipulating where you can manipulate one cell you can manipulate a section of cells a column or a whole row so i think that that's probably good for the the uh that first header but let's in fact let's put a code comment here um formats the header row just a header and then down here let's say that we want to manipulate a couple more things other miscellaneous things for example um ws.row2 let's set the style horizontal alignment equal to uh wow have the equals first center as well so row two which is that header row for our columns the id first and last name where i started the whole row and then along with that i'm going to say that row 2 style font bold equals true just set that as a bold style i think that's probably good and then let's say that uh ws dot column let's do column three which is that last name column and we'll say that the width of it should be let's go to 20 just to show you can change the width of a column after you've auto fit them so if you if you do this first and then autofit that'll overwrite this but if i do autofit first and then say i actually want to override that to something else you can do so so that way you could autofit the whole document and then manipulate one column that that maybe is just too large normally so let's again check our demos flow is nothing in there let's run this and go back to our demos folder and there's our our new file and we open this up and there's our cool report so we have let's zoom in a little bit here so you can see it we have our really big title here knows it's centered in these three blocks even though these three blocks are different um we've got our our different font size and different font color we have our bolded row two which is our our header row for our columns we have this column right here that's been centered so and this column right here is a different width than it would be normally if we had auto fit it like so all right so it was uh 20 something like that or so i'm not positive but somewhere around there so that's how you format your documents let me add multiple tabs down here just by just by manipulating this where you say add worksheet so i said i've been using ws for worksheet but it's always been main report well i could change this to create another worksheet and do more work and have uh you know more data on this excel file if we wanted to that's pretty common for when you want to do things like you have your first tab be the summary data and then you have other tabs with the data that supports the summary data maybe the uh the full data to back up that summary data and so on so a lot of stuff you can do with especially reporting but in general manipulating your excel file you can put borders around things you can put formulas in basically you can do whatever you want to do with excel now i do want to share one thing here we go close this and say don't save and let's open back up our demos and notice here we have a three kilobyte file i'm going to copy this i'm gonna paste it okay so there's our copy i'm gonna open up the copy and i'm going to just close it right down and it says do you want to save this this is a it's not a bug but it's something to be aware of so i'm gonna say hit yes because well i haven't changed anything but sure and if we look that now let's see if we can zoom in here this is the copy is 10 kilobytes versus three kilobytes for our youtube demo so why is there a difference there and why does it prompt us for saving it because if we open up this copy again and just close right down it doesn't prompt us to save and the reason why is because of what's actually happening behind the scenes so when ep plus creates our excel file for us they're not actually creating an excel file they are creating the um the data necessary for the file but it's not the same thing as actually using excel there's uh metadata and other things around that that get created when you actually use excel but the the benefit of using ep plus is we don't have to have excel installed on the server now if you did you could create a little script to open up these files save them and close them and that that would finish off the process of creation of a document but this is a very standard thing that happens whenever you generate an open excel or open xml file as an excel file without actually using excel this is a common to pretty much everything that uses um openxml so this is not a bug this is not a a missing feature it's just something that you have to understand about the files because technically these are zip files so if we were to put the dot zip extension here and then open them up you'll see documents and other things the xml documents in here for our file and if you compare that with our copy you'll find in here in the copy there's some differences as far as um our properties and other things that are in here so you can do a comparison here it's all metadata essentially that's been changed but just know that that's the difference is when you actually open excel it creates the rest of this media stuff so that's where the differences in file structure are so the first time you open that file you're gonna see that save dialog you can say no and actually keeps the size smaller but if you say yes it will change the file but not with any data it doesn't change any data it just changes some metadata so just be clear about that from the get go and that's not an ep plus thing versus something else okay that's a standard thing okay so you've seen how to write to an excel file but that's really half the battle let's figure out how to read from an excel file so to do that let's say list of person model let's call this people from excel equals await load excel file passing in the file again we haven't created this yet so let's control dot to generate that method and let's make sure this is async task and get rid of our throw exception so it's going to load in a list of person model from our excel file so how do we do that unfortunately it's not the easy process that it is to save to excel and the reason why is because in inside of our our objects we know the types and we know how to then put them into excel but getting them out of excel we have to figure out which columns go where and what range are you talking about and are you know are you done the end how you know where the end of the file is and all these questions that we have to figure out so we're going to do this i'm going to show you an example of how you would do this it would be a not manual process but a a custom process per file type you couldn't just throw random files in here without some work with generics and there is some really cool stuff you can do with generics i have done some work like this where you kind of throw any file you want at it and it loads it into strongly typed objects but it does take a lot more work to to plan out and do right and even so you gotta think through things like our header row which we have to you know account for our where it says our cool file or whatever it says um that wouldn't be part of our data so we have to make sure we don't include that when we're looking at importing data from excel so just know there's some things to think through but um this can be a really beneficial process i want to make sure you know how to do it first let's create a list of person model and this will call it output equals new and this is going to be the file that we create um to output our our list of person model from this method okay um one thing to note too if you did not upgrade net five you can't do this so you have to say new person model um that's the that's pretty much the only change i think that you'll see um come from my code to your code if you're not using.net5 all right so and don't forget you can download the source code um there's a link in the description so you can compare mine to yours if yours doesn't work and that's probably one of the first thing to check is to make sure that you've set yours to net five all right so using var package equals new excel package and we'll pass in that file again we're using the um the inline using statement instead of the curry brace model and we'll say await package.load async so it's going to load the file asynchronously the file does have to be there so make sure the file is there because i'm assuming the file is there i've been in a production application do some checks here to make sure the file exists and that it is in fact an excel file but load async will load this file assuming it's there now var ws for worksheet equals package dot workbook worksheets and instead of using a name i'm going to say the first worksheet all right and you can go through and figure out if worksheets exist and so on but i'm going to say just get the first worksheet we're going to work off of that one so now i'm going to create two helper variables int row equals three and int call equals one and it's going to help me uh with my rows and columns i'm saying row equals three because let's look at our excel file here now let's open it back up ah i deleted it no worries uh let's go to our save excel file right here so row one says our cool report don't want that row two which is this one right here is our headers so i don't want that one either i want to start with my data so that would be row 3 is where we start so while string dot is null or white space ws.cells row call dot value question mark dot to string and we're going to say um equals false oops i'm missing a paran in here all right so what what is all of this so i'm looking up the the cell and row 3 column 1 to start with and saying is row 3 column 1 is the value first of all not null because this question mark right here says if it's null then then throw this whole thing out because it we're done we can't evaluate this to be a string or not so if it's not null then do a two string on it the value of it and that value is not null or white space so it's looking the excel file and saying okay is there data in this column in this row in this specific cell and the reason why i'm doing this is because i'm saying i don't know when the last row in the file is and this is how i'm determining it if there's no data in that first column for a given row i'm saying that we're done there's no more data in the file because my assumption is with the id column there will always be an id number for record there might not be a first name there might not be a last name but there will always be an id number so that's how i'm determining when that last row is when i don't have any information in that row so this while loop's gonna keep going until it's null or white space in that cell okay so we've determined that whatever row we're on there's data in there so therefore we're going to say person model p equals new i really like that new syntax it keeps things shorter p dot id equals int dot parse ws cells at row call let's say dot value dot to string and why am i doing two string here well because this is actually an object and i if you don't say um if you don't say to string what's going to happen is it's going to pass whatever type it thinks it is which is a double so numbers get treated as doubles by default they sell that's a problem for ins because if i try and cast it to an int it's going to say you can't do that you can't cast a double to an int so this is a shortcut way of doing it which is to say hey take that value output a string whatever it is don't care just get a string representation of that particular cell and then i can say in dot parse because i'm going to know that it really should be an int therefore that should parse just fine now i could do a try parse in here and do some more safety checks around this just in case excel through a a dot zero at the end or something like that but i think this will work just fine for our demo purposes at least and in the real world yeah you could do some more checks around this just just be very sure that you know the value is correct now for the next values things get easier ws cells uh row call plus one okay so that would be the second column and dot value to string because um oops that's not minus that's an equals because tostring represents the string value and we're storing it as string and is a string therefore life is good copy that line once more for last name and change that to plus two so now column plus two so that would be column three so one plus two is three um and that gives us our last name column and now we can say output add p and don't forget to say row plus equals one to increase that row number to the next row in line which is then i'm going to do a check for the while loop if you missed that line you will have an infinite loop where you look at the very first row over and over and over and over and over again don't do that all right after our while loop we can just return output and that gives us our our list of person model from our excel file so we can come back up to the top here and let's just say we can take this person model and say for each and we'll say var p in people from excel and we'll do a console.writeline with our string interpolation and say just really simple p dot id space p dot first name space p dot last name and then save that that's got output the people from our excel file so let's we have now we're saving to the excel file and then we're also reading from that excel file afterwards and loading to a different list just note we're not pulling from that same demo list so that um you know we're not we're not cheating here this is a brand new list that we're loading up let's run this and i'm going to drag us over here and notice it says tim corey sue storm and jane smith it load all three of those from the file so it knows there were three records and here are those three records they're now strongly typed inside of c sharp from excel just to show you that the power of this let's take away the um the save excel file it's not going to save it anymore we're just going to work off of this file and read from it and let's open this file up and let's add some more ids here um bill uh bill smith and let's say mary white okay so two new records they're not in c sharp but when i go run this bill smith and mary white so it brought in those additional people because they were in the file was that how is that significant well because you can give us excel file to someone and say fill out this information and then they have it automatically loaded into x into your c sharp application and processed maybe put in a database maybe have work done on it or whatever you want to do but this is now a potential user interface excel is for your users you can give an excel file and say fill this out and they know how to do it they can work with it no problem they'll fill it out and then you can run it through your c-sharp application import the data work with it manipulate it and so on or if you have data that's been exported from another system into excel you can then take that data and use c-sharp to bring it into your main system or a different system to work with it so a lot of cool stuff you can do here with both saving and loading data with excel now there is a lot more that you can do with excel you can do things like graphs you can bring in images um you can do charting always really cool stuff you can do excel you can do with ep plus sparklines and so on so there's a lot more to cover but i think those are the main things that you will really need excel for is that especially that that saving to excel file that right there with just a few lines of code you can output your model to excel and call that your report so many of you have asked me for free reporting solutions and there's not great options out there there's not great systems we're going to say yeah there's a free reporting solution for c sharp but this is well not necessarily always free not free for commercial but free for non-commercial and i believe for open source project it's a great option for outputting data and even if you are commercial i have to pay a little bit the nice thing is you don't have to pay anything until you're actually going to use it in production so you can create your demos you can show this off your boss you can build even your sample application to show off what it could do for free and show it all off your boss and say hey it's gonna cost 300 i believe it's what it costs but um that's what you get out of it and that can be a really easy value sell you say here is a value you're gonna get day one and so that's um a kind of a an easier way to do reporting inside of c-sharp that might not cost as much as some of these more expensive and more complicated and time-consuming reporting solutions plus your users will almost always know how to use excel or at least open excel files up and do the basics with it and this can make their lives easier okay so that's it for working with excel if you have any questions or any thoughts leave them down in the comments i may do another video with another excel library in the future we'll see but i want to show this one off because i think this is the most um well-rounded solution out there on the web today so thanks for watching and as always i am tim cory [Applause] [Music] you
Info
Channel: IAmTimCorey
Views: 41,496
Rating: 4.9085312 out of 5
Keywords: .net, .net 5, .net core, .net core tutorial, iamtimcorey, tim corey, c#, epplus, epplus read excel c#, epplus .net core, epplus c#, epplus write to excel c#, epplus commercial license
Id: j3S3aI8nMeE
Channel Id: undefined
Length: 55min 42sec (3342 seconds)
Published: Mon Jan 25 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.