The attached file is a simplified version of my web export to excel template. Can you please show me what to change it to allow this to work in my desktop windows form app and windows services? I’m having trouble finding it in your examples. Thanks!
Hi,
Thanks for your posting and using Aspose.Cells for .NET.
Please use the following modified code in your desktop (WinForm or Console) application.
Also, I recommend you to download and try the Latest Offline Demos of Aspose.Cells for .NET to be familiar with Aspose.Cells API quickly which you can find from theses links.
These demos can work with Visual Studio 2005, 2008 or 2010. Please read the readme.txt file before running the demos.
Below is a sample code after modification. I have highlighted the changes in red colors.
C#
//Your source file name
string strTemplateFileName = @“F:\Shak-Data-RW\Downloads\source.xlsx”;
Workbook wbook = new Workbook(strTemplateFileName);
Worksheet sheet = wbook.Worksheets[0];
using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings[“SQLConnection”].ConnectionString))
{
SqlCommand cmd;
cmd = new SqlCommand(“xxx”, connection);
cmd.CommandType = CommandType.StoredProcedure;
connection.Open();
SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
//Import the datareader object to the sheet cells
sheet.Cells.ImportDataReader(dr, false, 1, 0, true);
dr.Close();
}
sheet.AutoFitColumns();
//Set the sheet as an active sheet.
wbook.Worksheets.ActiveSheetIndex = 0;
wbook.Save(strTemplateFileName + “.out.xlsx”, SaveFormat.Xlsx);
I've tried that initially. I get the following errors when I try to build but with no warnings before attempting to compile:
Warning 3 The referenced assembly "Aspose.Cells, Version=7.2.0.5, Culture=neutral, PublicKeyToken=716fcc553a201e56, processorArchitecture=MSIL" could not be resolved because it has a dependency on "System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which is not in the currently targeted framework ".NETFramework,Version=v4.0,Profile=Client". Please remove references to assemblies not in the targeted framework or consider retargeting your project. GenerateRecurringEmailReports
And Also:
Error 1 The type or namespace name 'Aspose' could not be found (are you missing a using directive or an assembly reference?) C:\Users\RDouglas\Documents\Visual Studio 2010\Projects\GenerateRecurringEmailReports\GenerateRecurringEmailReports\Service1.cs 11 7 GenerateRecurringEmailReports
Error 1 The type or namespace name 'Aspose' could not be found (are you missing a using directive or an assembly reference?) C:\Users\RDouglas\Documents\Visual Studio 2010\Projects\GenerateRecurringEmailReports\GenerateRecurringEmailReports\Service1.cs 11 7 GenerateRecurringEmailReports
Should I use a different version of the dll?
Hi,
VS.NET
project’s Target framework is “.NET Framework 4 Client Profile”, then you should use the Aspose.Cells.dll component file located in “net3.5_ClientProfile” folder @ your installation directory. If your VS.NET
project’s Target framework is “.NET Framework 4” or other, then you may simply use the Aspose.Cells.dll component file located in “net2.0” folder.Wow. That did it. Thanks.
Hi,RandyCDouglas:Wow. That did it. Thanks.
Thanks for your feedback.
We are pleased to know that your issue is now resolved.
Let us know if you face any other issue, we will be glad to assist you further.