Trigger excel solver from vb.net web app - asp.net

Using vb.net, visual studio 2013 and excel 2010.
I have a web page and when a button is clicked values are passed from the page to excel ( a presaved formatted copy). I then want to run the solver add in (which I have also preconfigured). I have been searching for a while now and cannot find a way of doing this.
The below is the code I use to open the excel application
Dim xlApp As Excel.Application
Dim xlWorkbook As Excel.Workbook
Dim xlWorksheet As Excel.Worksheet
xlApp = New Excel.Application
xlApp.Visible = True
xlApp.DisplayAlerts = False
xlWorkbook = xlApp.Workbooks.Open("c:\temp\RTO.xlsx")
xlWorksheet = xlWorkbook.Sheets("Optimiser")
Another curious problem that may be related is when I open excel from the web page the solver addin is enabled in excels options but does not appear in the data ribbon tab. If I disable and enable it in the options it comes back.
UPDATE
I tried the following code
xlApp.Run("C:\Program Files\Microsoft Office\Office15\Library\SOLVER\solver.xlam!Auto_Open")
But it errors with the following
Additional information: Cannot run the macro 'C:\Program
Files\Microsoft Office\Office15\Library\SOLVER\solver.xlam!Auto_Open'.
The macro may not be available in this workbook or all macros may be
disabled.

Ok, so
1) a website that populates excel with data and then streams the excel to the client.
2) the client then fill out or manipulates stuff in the excel.
3) Then clicks a button to solve and perhaps submit the excel...(where you are stuck)
Step 3 could be accomplished with a small 'one click application ' aka 'clickonce', whereas the application is online and served from your site. You could take one cell of your excel and have it open IE and point to the installer, and even pass a parameters (be sure to allow params to pass in the app) as to where the excel was located. Then the app could interop with the excel and do its stuff, perhaps even deliver data back to the server.

After further research and thinking about my problem, I came up with the following.
I cannot find any help about triggering solver from within my vb.net code but you can trigger a macro.
First I added the following code which loaded solver.xlam into excel once it had launched.
xlWorkbook.VBProject.References.AddFromFile("C:\Program Files\Microsoft Office\Office15\Library\SOLVER\solver.xlam")
I then created a macro in excel to launch solver. Once done I added the following line of code into my web page. Runsolver is the name of the macro.
xlApp.Run("RunSolver")
Hope this helps someone else down the line

Related

Smartsheet api workspace sheet set

Thi is my first question.
I'm developing an exportation from our SQL based ERP to smartsheep.
We are developing in .NET (VB).
I'm creating / uploading sheet and creating data in row without problems.
My actual and almost last trouble is to be able to set a specified workspace...
Example.
I Upload a template XLSX file to smartsheet. I populate it with all the data i need to put inside, than (and here we are) i would like to set to the uploaded Sheet a specific workspace...
I'm using nuget smartsheet-csharp-sdk Version 2.126.0
Thank you for any reply.
This is more or less my code:
Dim smartsheet As SmartsheetClient = New SmartsheetBuilder().Build()
Dim sheet As Sheet = smartsheet.SheetResources.ImportXlsSheet(Dim XLSFILENAME as string, Nothing, 0, Nothing)
Than i have my build / upload rows code...
but no idea on how to set the workspace....
With the import ImportXlsSheet you can't set a destination, the sheet will be created at the root (home) or smartsheet.
You've to create the sheet, and by the response you should have access to the sheetId created.
With a second call to the API, move the sheet to the specific workspace. see also : https://smartsheet-platform.github.io/api-docs/?csharp#move-sheet

Restoring MS Project Views

I'm running a user defined script that changes the view during the course of its computations. When I launch the VBA script, the view is in no particular filter, table or view name. I want to restore the view just as it was before the user launched the script including which task has the focus. It seems like naming the view as the first step when the script launches and saving the task which has focus then activating the view and focus at the completion of the script is a potential way to do this but I'm not having any success. I would delete the named view at the end of running the script. Any suggestions or point me to previous discussions on this forum that may have answered; my search didn't reveal any.
Rod Gill suggested the following but unless I'm doing something wrong it doesn't appear to work.
Dim OrgnlID As Long
Dim OrgnlView As String
Dim OrgnlTable As String
Dim OrgnlFilter As String
OrgnlView = ActiveProject.CurrentView
OrgnlTable = ActiveProject.CurrentTable
OrgnlFilter = ActiveProject.CurrentFilter
OrgnlID = ActiveCell.Issue
' place your code here that does the view manipulations
' followed by the lines below to restore the view before manipulations
ViewApply OrgnlView
TableApply OrgnlTable
FilterApply OrgnlFilter
EditGoTo ID:=OrgnlID

How to use ReportingCloud in asp.net web site?

Recently I have started to work with SSRS and found ReportingCloud. It says
ReportingCloud provides an open source quality implementation
as an extension of the RDL specification
I haven't found any tutorial/documentation on how to use it in sourceforge or via google search.
Can anyone give an walk-through/example on How to use ReportingCloud?
There is one partial example available at http://sourceforge.net/projects/reportingcloud/forums/forum/1116661/topic/4571059.
The example takes an existing RDL file, parses and executes it and then places the HTML output into an asp.net Literal Control for display in the browser.
That code snippet is repeated here:
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load("C:\MyFolder\MyReport.rdl");
RDLParser rdlp = new RDLParser(xmlDoc.OuterXml);
rdlp.Parse();
MemoryStreamGen ms = new MemoryStreamGen();
ProcessReport pr = new ProcessReport(rdlp.Report, ms);
pr.Run(null, OutputPresentationType.ASPHTML);
// Dump memory stream (HTML Text) to an out-of-box ASPX Literal control
this.LiteralReportHtml.Text = ms.GetText();
To do this you'll need a reference to ReportingCloud.Engine.
I'm not sure exactly what your bigger goals are but I'd like to draw your attention to another open source project on GitHub called My-FyiReporting https://github.com/majorsilence/My-FyiReporting
Just like ReportingCloud, My-FyiReporting is a fork of FyiReporting (which has gone dormant).
The big difference as far as you are concerned is that My-FyiReporting has ASP.NET samples and an ASP.NET user control link. This might be the fast way to get to what you need.
File ORIGINALPROJECT.TXT from ReportingCloud says:
The ReportingCloud is a fork from the original project fyiReporting
4.1 (http://www.fyireporting.com).
File readme.md from My-FyiReporting says:
My-FyiReporting is a fork of fyiReporting. I cannot stress this
enough. This is a FORK. The main purpose is to make sure that I have a
copy of fyiReporting since that project seems to be dead.

Naming of Sheets using Asp.net SSRS 2008 (RDLC) for export to Excel

I'm working on a VS 2008 asp.net webforms application in which it contains an existing RDLC (Client file, and NOT the RDL Server side file).
The problem is upon exporting to excel, all of the worksheets are not named properly, i.e. Sheet1, Sheet2, etc. I have found many examples on exporting data, on SQL Server 2008 R2 feature of RDL, however I am in need of a RDLC solution?
Does anyone know about how to either "fix" this or do some sort of post processing to rename the tabs so the customer doesn't end up seeing Sheet1, Sheet2, Sheet3,etc.?
Application is choosing the path of the RDLC file
Adds DataSource
Chooses xls
Does all the Responses
I see this Stackoverflow link How to get named excel sheets while exporting from SSRS, however:
Can't do the Macro
Can't do the export as SSML
I am NOT using RDL / SQL Server 2008 R2 SSRS, thus the other answers are misleading for people using the RDLC
Sheet renaming isn't supported with the version of RDLC report. I'm guessing you can't upgrade. So here's a work around: Save the report to a file as normal. Then open it again using Microsoft.Office.Interop.Excel or any other Excel library to rename the sheets. Once you do this save and you're done.
using Excel = Microsoft.Office.Interop.Excel;
Excel.ApplicationClass xl=new Excel.ApplicationClass();
Excel.Workbook xlBook;
Excel.Worksheet xlSheet;
string filePath = Server.MapPath(#"\report.xls");
xlBook = (Workbook)xl.Workbooks.Open(filePath,Type.Missing,
Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing
,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing);
xlSheet = (Worksheet)xlBook.Worksheets.get_Item(1);
xlSheet.Name = "New Sheet Name";
xlBook.Save();
xl.Application.Workbooks.Close();
List of different libraries that you can use if this one doesn't work for you: Free Libraries
1. Close XML Library - http://closedxml.codeplex.com/documentation
2. Open XML SDK - http://msdn.microsoft.com/en-us/library/bb448854.aspx
3. NOPI - http://npoi.codeplex.com/
4. CarlosAG - http://www.carlosag.net/Tools/ExcelXmlWriter/
Paid Libraries
5. Spreadsheet Gear
6. Smart XLS
7. Office Writer
8. Spire
I would upgrade to the RDL 2010 schema - it supports Excel Named Sheets (amongst other useful enhancements):
http://msdn.microsoft.com/en-us/library/ee960138.aspx
Your not going to be able to do it.
http://social.msdn.microsoft.com/forums/en-US/sqlreportingservices/thread/54caf25b-b17b-474c-aa47-fc884f90af03
http://go4answers.webhost4life.com/Example/reportviewer-eport-excel-naming-sheets-157612.aspx
http://forums.asp.net/post/4140154.aspx
This may help for post processing using excels xml dialect:
http://spacefold.com/lisa/post/Changing-the-Sheet-names-in-SQL-Server-RS-Excel-QnD-XSLT.aspx

Alternative to Excel as ASP.Net Report Generator

I use excel through vb.net/asp.net to generate reports from a web page and then send the file down to the user. We've had some issues with Excel being super slow/inefficient/not closing (even when we keep track of the process id and try to kill it in code...). So I'm looking for some flexible alternatives. We need a replacement that can:
Allow for inidivdual cell formatting including borders (different settings on each side), background colors, font styles/coloring, etc...
Allow for cell merging
Allow for formatting (bolding in this case) of a portion of the text inside of a cell while leaving the rest of the text unchanged
Image insertion/repositioning inside a cell (not crucial)
Multiple Worksheets per Workbook
These are all the features I can think of off hand, any help or suggestiong at alternative libraries to look at would be appreciated. We are running Excel 2007 on the server but we are rolling out Office 2010 to clients so I think that might open the doors for some more supported file formats, if that helps.
After looking through the various options and performing more independent research I ended up using EPPlus, which you can get # http://epplus.codeplex.com.
Thanks for all the suggestions.
I recommend you to use the DevExpress.XtraReports from DevExpress. It is a Licensed product, but offers you a friendly toolkit for generating great and complexity reports. It is well documented and easy to use, once you define a template (REPX) you can populate it with data by assigning to each element a value as well as using [mail merge] feature which will be automatically replaced once you bind with data the report. In the core of such technology is a well OO design of classes. Once you generate the report you can export it to the most common formats: XLS, HTML, PDF, RTF...
public void GenerateReportFile(string rptFileName, string param1, int param2)
{
XtraReport report = null;
try
{
report = new XtraReport();
//-- loads the layout template (repx file)
report.LoadLayout("SomeDirectory\report_template.repx");
//-- assign data to report controls
report.FindControl("Label1", true).Text = string.Format("{0:dd/MM/yyyy}", fecha1);
report.FindControl("Label2", true).Text = string.Format("{0:dd/MM/yyyy}", fecha1);
//-- gets data from some Data Acces Layer method and assig it to the report DataSource property
DALReport dal = new DALReport();
report.DataSource = dal.GetReport1Data(ExpEmp, param1, param2);
report.DataMember = "data";
report.ExportToPdf(rptFileName, options);
}
catch { throw; }
finally { if (report != null) { report.Dispose(); } report = null; }
}
For more information refers to: http://demos.devexpress.com/XtraReportsDemos/
There is another free library for .Net iTextSharp, this library
was originally written for Java, then was translated to C# for .Net
usage. The library is mainly for PDF documents creation but some
versions also supports XLS documents creation.
GNU plot is a little bit of a pain to get to run on windows but it is a an awesome tool
It sounds like you are using a library that opens Excel and uses MS Office Excel objects to create the Excel file. Since you are using 2007 and above, you may want to consider creating the Excel file manually using a library that creates the XML (therefore, Excel doesn't open at all).
Check out ExcelLibrary.
While doing a search on this, I found this page (on StackOverflow) that provides some sample code.
Office Web Components (though dated) is free and has worked for me in the past.
If you want to spend the loot, Aspose Cells is a good way to go also.

Resources