Export Excel file from C# web app project - javascript

The question is brief because I don't exactly know how to start approaching the problem to understand it.
I have identified the .aspx file (in my C# web app project) where an export picture is located, when pressing on it an .xlsx can be downloaded (with content taken from the database), where do you suggest to start the investigation to understand just HOW this file is generated? - I'm interested in the SQL query that is executed to populate the excel.
You may think of it in another way, if this was given you as a task, how would you sketch a plan to generate an excel from a C# web app project based on an SQL query that populates Sheet1?
PS it's not a macro file. Thank you for any pointers.

Just don't use the excel COM for a webapp. Instead check out Epplus or maybe the Apache POI project has something that works with .NET for generating excel files.
Basically you'll just run your database query, put the data in the worksheet w/ your formatting etc, then send it off to the client. You could stream it out or post it somewhere for download later.
You have lots of options just need to break this down into parts.

To answer the initial question "where do you suggest to start the investigation to understand just HOW this file is generated?":
Investigate the export picture with your browser tooling, for instance in Chrome you can do a inspect element from the context menu when you right click on the image. Some possibilities:
A form is submitted ASP.Net style, find the function it is calling on the target ASPX/ASHX page. Set a breakpoint in that function, hit it, follow the code.
Javascript code is run, probably doing a JSON call to a service MVC/WebAPI function. Set a breakpoint in that function, hit it, follow the code.
Still can't find it, search for the word ContentDisposition in the code, this is needed 99% of the times to send files to the client browser as an attachment.

Related

Would like to write a javascript that helps me to find documents in a folder

I would like to write a js for an offline website (located on a local Windows server or any other server). It's supposed to look for files like PDFs in several directories and display them as search result on the "website", which isn't a real website, since it's on a local server and not in the web. The PDF is supposed to open in the browser after clicking it. I already have this kind of search engine as a php file, which I wrote with some help from friends. I also want to share this site with other friends. Basically I'll send them the whole folder with the html - document (or the .php site), so they can use it to search for certain pdfs in the folder. Its like a offline wiki for medical research documents. But I don't want them to always install php on their local servers, so they can run my php-searchmachine, thus I need to write it new as a javascript. By google and stack overflow I came across this solution https://www.codegrepper.com/code-examples/javascript/find+file+in+directory+javascript but it seems like that this needs node.js, so all have to install node.js, which is similar to installing php, I guess (im not familiar with node.js). Also I'm not sure if node.js is running on a normal client or server, which is not a webserver.
How can I start with such a project? Is javascript the correct attempt to solve this?
Windows Search has the ability to search PDF contents when boosted by a PDF (index) iFilter, this means the user can search and find instantly a new search word or a saved search it took only a second to hand enter this search (actually took longer to save for double click next time) just for illustration I chose a word I knew was in one file and actually found it is also in two other PDFs.
The problem for your JS coding is how to use JavaScript to interface with Windows Search since using explorer I could not run that search on a remote server shared library drive (I could see their contents as per second screen but for search, had to pull a local library copy down to my documents) and that is where your JS skills come into play. Personally I would avoid JS and use a VLC method to share view via a remote Lan server or simpler invoke a plain text indexed local copy of remote files for download as and when required.

Print Portion of the Browser Window to PDF and Send To Server to be Faxed

Like the title says, I have a requirement to print a part of the browser window to PDF and then send it to the server so that it can be faxed. I have already found a faxing service so the real problem is in figuring out how to generate the pdf to begin with. I have come up with several options to do this, however all of them come with significant downsides. They are:
Use window.print() on a button click along with print media queries and have the user download the resulting PDF and re-upload it to be faxed. The problem with this is that it is a multi-step process and my users would prefer to just click a single button
Use a library like jspdf to generate the pdf, output to a byte array and upload it to the server. This will work, however it looks terrible because I lose all styling and my print media queries will not be applied. So far, this is my best option
Render the HTML server side and generate a PDF from that. This will work fine, however it requires duplicating all of the work I have done client side (this is a SPA app) along with duplicating the maintenance.
Use a rendering service or library to run the client side application in a headless browser and generate the PDF from that output. This would be very complicated from a security perspective as the application lives behind a login page.
I would appreciate any suggestions not listed above as well as any advice on how to eliminate the cons posed by these options. Thanks in advance!
Looks like using jspdf to render the PDF along with a library such as html2canvas to convert the printable region into an image to preserve styles will get the job done. It has taken some work to configure everything properly (and I'm not through yet) but I am confident this solution will be effective.

Extract, edit and save .dwg meta data

I'm building an app that deals with engineering projects. Part of the app requires uploaded CAD files (.dwg) to be assigned to equipment.
What I would like to do is edit the meta data of each file to contain a reference to the part it has been assigned to.
So if a file was linked to part X1234567 I'd like to add this 'tag' to the meta data of the CAD file.
I have been working with the Forge API and see there is an endpoint for extracting meta data documented here but I see no way to put edited data back in to the file.
Is there any way to use the Forge API, PHP, Java or JS to write a method to extract metadata, edit it then save it back to the file?
I'm open to any suggestions to how I can do this.
Thanks
I should also note Java is my last choice, sorry Java guys, I'd really like to keep this in PHP or JS, but can dust off my Java skills if that's the only way.
I read your question as you want to edit metadata within a DWG (not the data that is attached to the DWG file in A360). Presumably you want to edit Xdata or Xrecords. To do this, you should use the Design Automation API (not the Model Derivative API).
The Design Automation API is essentially a headless version of AutoCAD running on an Autodesk server (the API used to be called AutoCAD I/O). You can use this API to run any script against any DWG as long as you don't require user interaction. You can also run custom actions (commands) that you have defined using the AutoCAD LISP, .NET or ObjectARX APIs (i.e. you can upload your own script or add-in to the service and run it against your DWG.
Documentation for Design Automation API is here - https://developer.autodesk.com/en/docs/design-automation/v2/overview/.
There are some samples on GitHub here - https://github.com/Developer-Autodesk/AutoCAD.io.

How do I export from an HTML table to an excel spreadsheet?

~Opposite of this question
I'm working with the google drive javascript API, and I've used it to add a "Save to Drive" button in my web application. With this save to drive button, it requires you to give the location of the file in order for it to be downloaded. Let me explain the page
There is an html form, and you fill out the fields and click "Check", it queries the database, parses those results into an html table that can be viewed from the webpage. The results aren't saved to a file. There's not enough space to scale a solution that saves these reports and keeps them on the server. To be clear here I am looking for being able to provide a downloadable spreadsheet generated from the html table.
There is webViewLink, but this implies that a file exists. Using PHP or javascript to make a temporary file out of the html data could work -- if there is no html to google spreadsheet converter, an html to spreadsheet parser would do the trick. But I'm trying to do this with as little custom coding as possible, as it is part of a larger project and I shouldn't get stuck on coding things that might already have robust solutions.
Even it being google drive isn't all that important. Are there other libraries that would make it easy to download html tables as spreadsheets? The reason I'm asking for a quick solution like a library is that this isn't a main feature of my project, otherwise I'd spend a bit of time on it. It's just something shiny that I can show got done during the timeframe, because higher ups don't appreciate back end refactoring as much as they should.
PHPExcel might work, but I get the feeling it will use storage on the server. The old system of copy pasting the data to a spreadsheet works too, but I'm trying to make it one-click, bam, excel sheet, without having to ask for a bigger VM
You can use jQuery to download an excel spreadsheet. Look at this JSFiddle
$("#btnExport").click(function (e) {
window.open('data:application/vnd.ms-excel,' + $('#dvData').html());
e.preventDefault();
});
Have a look here too. Next time, try widening your search criteria.
You could try Excel Online. This has a JavaScript API.
See http://microsoft-office-add-ins.com for more information.

How to show browse for FOLDER window(not browse for file)using just JSP and javascript?

I need a code for how to browse for folder (not file) using JSP and Javascript.
I looked for the JAVA code for browse for folder using JFileChooser library but I want the default window to be opened (which opens in browse for file).
I'm developing a webapp which will scan the folder based on the path and will generate the output.
Thanks in advance.
1.I need a code for how to browse for folder (not file) using JSP and Javascript.
Javascript does not have access to the file-system due to security reasons, as this answer says and also this answer.
So you would have to use flash or java applet as suggested in this answer or else you would have to wait till the time HTML5 File API matures :-)
But, if your requirement is that your a User (may be with administrator rights in the application) logins to the web-application through a web-browser and wants to scan (view the contents of) the particular folder on the server side (where the web-app is deployed and not the file system on his own machine) then you can use the suggestion given in this answer, just to elaborate on this:
Have a <form> which will have a text-box (to take the folder name or full-path) in the JSP, on submit of this form a request will be sent to the server.
The response would be list of files (List<String>) in that particular folder passed through the request.
you can also submit the request through ajax in which case you would return a JSONArray as suggested.
Now on the Server it would be normal Java File API stuff to fetch all the files in the folder you get from the request.
Sorry to say this but I don't think you would get a ready-made code to do what you want and that is not how things work on SO.
2.I looked for the JAVA code for browse for folder using JFileChooser library
You said you are building a web-app right? JFileChooser is a Swing component and as far as I know cannot be used in JSP to achieve what you desire.
3.I'm developing a webapp which will scan the folder based on the path and will generate the output.
The steps are explained in point (1).
Hope this helps and gives relevant hint and direction to go forward.

Categories

Resources