Domanda

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.
        }
    }
È stato utile?

Soluzione 5

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.

Altri suggerimenti

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:

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.

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.

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/

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top