0

I have created a simple and basic Hello World template with the sample coding I found in OfficeWriter. However, I want to save the output in a folder inside the computer, not store online (web)

The website have already stated how to save to a folder but it is not working in my case. Anyone can help on this? By the way, I used a console application to do the coding.

The error mentions that I must add System.Web reference which I think it is not necessary since I am not doing a web or something.

    using SoftArtisans.OfficeWriter.ExcelWriter;

    namespace ConsoleApplication1
    class Program
    {
        static void Main(string[] args)
        {
            ExcelTemplate XLT = new ExcelTemplate();
            XLT.Open(@"C:\Users\administrator\Desktop\Hello World.xlsx);
            DataBindProperties dataProps = XLT.CreateDataBindingProperties();
            string value = "Hello World";
            XLT.BindCellData(value, "DataValue", dataProps);
            XLT.Process();
            XLT.Save("Output.xlsx"); //this coding is giving me problem.
        }
    }
CHOCOx33
  • 25
  • 1
  • 1
  • 7
  • You need to provide the details of the error in order for us to assist you. – mason Jun 25 '13 at 01:45
  • The error goes like this, The type 'System.Web.HttpResponse' is defined in an assembly that is not referenced. You must add a reference 'System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f711d503a' – CHOCOx33 Jun 25 '13 at 02:08

5 Answers5

3

Note: I work for SoftArtisans, makers of OfficeWriter.

Although most of our customers use OfficeWriter in .NET web applications, OfficeWriter can be used in any type of .NET application.

All OfficeWriter objects (ExcelTemplate, ExcelApplication, WordTemplate, and WordApplication) have four output options:

  1. Save directly to disk
  2. Save to System.IO Stream
  3. Stream the generate file to the client as an attachment
  4. Stream the generated file to the client to be viewed in the browser. This only works for Internet Explorer and if viewing Office files in IE is enabled.

The Save method has a dependency on System.Web due to the Save() overloads that use the HttpResponse object. I know customers have run into trouble with the dependency if they were using the .NET 4 client profile because a reference to System.Web is not included automatically. I believe the same is also true for projects like console or forms applications.

To save a file to a particular folder on disk, you will need to provide the full file path to the location on disk. For example "C:\Reports\SampleReport.xlsx". You can use .NET code to help resolve the full file path before passing that value to OfficeWriter.

Here are a couple posts I found that discuss how to get the full file path from a .NET console application:

Community
  • 1
  • 1
AlisonB
  • 395
  • 1
  • 6
0

According to the ExcelTemplate.Save() documentation, the file is being saved to the server, even though you do not think it is. Since it is trying to save to the web server, System.Web is needed to resolve the physical path on the server.

Karl Anderson
  • 34,606
  • 12
  • 65
  • 80
  • Yes, it is. But I dont want to save it to the server before saving it into a folder. Rather, I prefer to save it offline as in store into a folder. it is more of a window form/console application instead of a ASP.net, hence my tags which shows C# only. – CHOCOx33 Jun 25 '13 at 02:06
  • Okay, I understand what you are trying to do, but I am not sure if this is possible with the ExcelTemplate library you have chosen to use. I recommend reading the documentation or contacting the company and asking them for help or if they have a library that does what you wish. In short, the library you are using is working correctly and you are not understanding how it is intended to be used. Either switch libraries or find out if they have a non-Web-based solution. – Karl Anderson Jun 25 '13 at 02:26
  • Wishing for a car to be a spaceship does not make it a spaceship; a car will not fly you to the moon just because you think it should. – Karl Anderson Jun 25 '13 at 02:27
  • Alright, I will try contacting the technical support on this. And actually, I found in older versions that it can also save the output in Window Form. I will try to check all the sample tutorials if it is possible to save it. Btw, interesting analogy you have here and it is true lol. – CHOCOx33 Jun 25 '13 at 02:48
  • @ChongdingDinoLee - Thanks, just trying to make a point. I am sorry that the library does not do what you want out-of-the-box. Good luck with getting it working or finding an alternative. – Karl Anderson Jun 25 '13 at 03:00
  • by the way, I figured out that I might not have added the web reference so I added. It worked like magic, managed to save the output. I might have forgotten to add it. – CHOCOx33 Jun 25 '13 at 03:23
0

You are using the wrong tool then. Directly from the documentation of Excel Writer 7...

SoftArtisans ExcelWriter is a high-performance pure .NET solution that generates native Microsoft Excel spreadsheets on a Web server. A few simple lines of code generate editable presentation-quality spreadsheets that can be saved on the server or viewed instantly by thousands of concurrent users.

http://wiki.softartisans.com/pages/viewpage.action?pageId=3114609

Look into using Visual Studio Tools for Office or some other library to satisfy your local Excel needs.

mason
  • 31,774
  • 10
  • 77
  • 121
0

You should try adding the System.Web reference to see if that fixes your problem. The System.Web assembly is already installed with the full .NET framework, so it doesn't change anything if you reference it or not. Maybe it will detect that you're not in a web application and save it anyway, but it needs the reference to do so.

Alternatively, use the open source EPPlus project to create Excel spreadsheets and System.Web will not be required - http://epplus.codeplex.com/

Wayne Bloss
  • 5,370
  • 7
  • 50
  • 81
  • Well, I am to use the OfficeWriter for some reasons and I need to find out how to save the output via offline (in folder) instead of online. And yes I did tried the way you mentioned but not to avail. – CHOCOx33 Jun 25 '13 at 02:46
  • Maybe you can trick the library into thinking that it's running in a web application. System.Web can be useful outside of IIS. Also, you could run a small web server inside of your console application with Cassini or something. See http://ultidev.com/products/cassini/ or https://code.google.com/p/cassini/ – Wayne Bloss Jun 25 '13 at 03:20
0

Okay, I found the answer to that problem, I just have to add the web reference to the project and it worked like magic. Once again I thank you all for the help rendered.

CHOCOx33
  • 25
  • 1
  • 1
  • 7