How to send excel file directly to printer or print html code? - asp.net

I have an ASP.Net 3.5 (C#) site that loads an excel file and then I want to print on a label printer at teh user's default printer?
Excel File is populated on sheet1
Print Area has been set in the file
When I print from excel to the label printer it prints fine.
I would like to send the excel file to the user's default printer. and have it automatically print the print area or the first sheet.
I would be open to sending a HTML String that has my data formatted in a table if that is possible. That would eliminate any need for the excel file.
Microsoft Excel is not installed on the webserver so using the Excel Refrence is out. But I do have the Microsoft Office SDK 2.0 and can use that if needed.
Thanks in advance for any tips or any directions.

Anything you could do manually, you can record using the macro recorder and figure out the code. Here is a generated code for sending files to my printer:
Application.ActivePrinter = "HP LaserJet P2014 on Ne03:"
ExecuteExcel4Macro "PRINT(1,,,1,,,,,,,,2,""HP LaserJet P2014 on Ne03:"",,TRUE,,FALSE)"
You could change the variables to match your own printer

Related

mPDF to output a local file + file inline to the browser

I wanna know if i can output a pdf, using mPDF, to a destination as well as a preview in the browser at the same time. ie. I+F at the same time.
I: send the file inline to the browser. The plug-in is used if
available. The name given by filename is used when one selects the
"Save as" option on the link generating the PDF.
F: save to a local
file with the name given by filename
My current code is like this:
$mpdf->Output($OutputLocation,F);
$mpdf->Output();
exit;
It can export the pdf file to $OutputLocation successfully, however, in the browser, it shows:
mPDF error: Some data has already been output to browser, can't send
PDF file
In the documents of mPDF, it has only show one option for one time, any methods to do both in the same output process?
http://mpdf1.com/manual/index.php?tid=125
Please help, thanks.
It turns out that it is an issue on QNAP that their default php.ini is not allowing output buffering.
To solve this, I have edited the php.ini in the WebUI and change the output buffering to 4096. Then it works again.
output_buffering = 4096

Access Macro Enabled Excel on Webpage using asp.net

I need to access macro enable and external sourced excel 2003 calculator from asp.net web page. Excel accepts few values and returns some numbers post calculations.
Users are not allowed to amend/access the excel from office hence need web access to use the excel calculator features where user enter the values on webpage and pass to Excel and display results on webpage.
I tried to use sharepoint excel services due to macros's and external source on the excel file it fails excel services capability.
I would appreciate if anyone can point me in right direction
You can try EasyXLS Excel library. It can be integrated in ASP.NET web pages. It reads xls file macro enabled files and includes a calculator similar with the one from MS Excel.
// Create an instance of the class that read XLS files
ExcelDocument workbook = new ExcelDocument();
// Read XLS file
workbook.easy_LoadXLSFile("Excel macro enabled.xls");
// Get a sheet and compute the formulas
xlsWorksheet = (ExcelWorksheet) workbook .easy_getSheetAt(0);
String sError = xlsWorksheet.easy_computeFormulas(workbook, true);
// Check the result of the formula
String result = xlsWorksheet.easy_getExcelTable().easy_getCell(3,0).getFormulaResultValue();
To display the existing values and enter later other values you can use this code:
DataSet ds = workbook.easy_ReadExcelWorksheet_AsDataSet(xlsWorksheet);
and set the DataTable as data source for a GridView for example:
http://www.easyxls.com/manual/FAQ/import-excel-to-gridview.html
EasyXLS has also some open source code (more complex) for displaying an Excel file in ASP.NET pages that can be adjusted to your needs:
http://www.easyxls.com/excel-to-gridview

Copy SSRS report content to clipboard

I have a button("Copy to Clip") in each row of a Gridview. On this buttton click I want to copy a SSRS report which is stored in database in binary format to Clipboard. Can somebody help please?
Thanks
Make an ajax call to your report server using url parameters to get the report in the format you want.
CSV would be a good format to paste into your clipboard.
http://localhost/reportserver?/Folder/report&param=val&rs:Command=Render&rs:Format=CSV
Then use a library like ZeroClipboard to paste the contents to clipboard. Its cross browser compatible as it uses flash.

Code to upload an excel file and read it in a dataset

I have a requirement , where in I have to upload an .xlsx file on the server and then read the file into a data table using c# , asp.net.
I need to get your file onto the server.
I need to open the (uploaded?) file.
I need to read the contents of the file, applying any nessesary data parsing.
I need to display the results in a gridview.
Help would be appreciated.

HTML Entity in CSVs

How do I add an html entity to my CSV?
I have an asp.net, sql server that generates html, excel, and csv files. Some of the data needs to have the ‡ entity in it. How do I get it to output to my CSV correctly? If I have it like this: ‡, then it gets screwed up but if I output it with the entity code, the CSV outputs that text.
Non-printable characters in a field are sometimes escaped using one of several c style character escape sequences, ### and \o### Octal, \x## Hex, \d### Decimal, and \u#### Unicode.
So just escape your non-ascii character C#-style and you'll be fine.
I'm not sure what you mean by "it gets screwed up".
Regardless, it is up to the receiving program or application to properly interpret the characters.
What this means is that if you put ‡ in your csv file then the application that opens the CSV will have to look for those entities and understand what to do with them. For example, the opening application would have to run an html entity decoder in order to properly display it.
If you are looking at the CSV file with notepad (for example) then of course it won't decode the entities because notepad has no clue what html entities are or even what to do when it finds them.
Even Internet Explorer wouldn't convert the entities for display when opening a CSV file. Now if you gave it a .html extension then IE would handle the display of the file with it's html rendering engine.

Resources