I've researched for days but I can not find anything to resolve this issue that I am having.
I have an excel file in .xlsx format that is updated through out the day. What I need to do is call a batch that converts it to .html. I will be taking that HTML file and copying it to a folder that automatically publishes it for internal uses at my company.
If anyone out there can help it would be greatly appreciated.
Excel lets you save as a web page natively. It also has a "single file" web page that combines all images/etc into a single file. It uses the mht or mhtml extension.
Const xlHtml = 44
Const xlWebArchive = 45
' Create an instance of Excel and open the workbook...
Set objExcel = CreateObject("Excel.Application")
objExcel.Workbooks.Open "C:\Folder\MyWorkbook.xlsx"
' Save the workbook as an HTML or MHTML page...
objExcel.ActiveWorkbook.SaveAs "C:\Folder\MyPage.html", xlHtml
' -or-
objExcel.ActiveWorkbook.SaveAs "C:\Folder\MyPage.mhtml", xlWebArchive
' Close Excel...
objExcel.Quit
If Some one looking for C#
Add Reference -> COM -> Look for Microsoft Excel, Microsoft Office then
using Excel = Microsoft.Office.Interop.Excel;
namespace ExcelToSinglePageWeb
{
class Program
{
static void Main(string[] args)
{
Excel.Application xlApp = new Excel.Application();
Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(#"C:\Users\name\Desktop\Work In Progress.xlsx");
xlWorkbook.SaveAs(#"C:\Users\name\Desktop\SomePage.mhtml", 45);
xlApp.Quit();
}
}
}
Related
I Already Digging for 5 hours but nothing to found. Is there any way to generate the rdlc into HTML. I tried RDLC to Image but my problem is, the generated image is slice in half.
Finally found solution(even though is not best answer). So basically, convert first to Excel then convert the excel into html then read all the text. I use the FreeSprite.XLS to convert the excel into html.
Freespire.xls Link
here is my code
private string GenerateHTMLReport(ReportViewer rv)
{
string mimeType,
encoding,
fileNameExtension;
Warning[] warnings=null;
string[] streamIds=null;
//Export report
byte[] exportBytes = rv.LocalReport.Render("Excel", null, out mimeType, out encoding,
out fileNameExtension, out streamIds, out warnings);
//convert to excel
FileStream fs = new FileStream("report.xls", FileMode.Create);
fs.Write(exportBytes, 0, exportBytes.Length);
fs.Close();
Workbook workbook = new Workbook();
workbook.LoadFromFile("report.xls");
//convert Excel to HTML
Worksheet sheet = workbook.Worksheets[0];
sheet.SaveToHtml("report.html");
string html =System.IO.File.ReadAllText("report.html");
return "";
}
generated HTML Code.
generated HTML in Preview.
Hopefully someone will found it helpful.
I would like to know if there is a way to create a link (Using HTML) to open an attachment embedded in the pdf document.
Something like this...
Open the attachment file or Open the attachment file
Any suggestion or recommendation?
Thanks
I have been able to implement this scenario after reading the next useful post
https://groups.google.com/forum/#!topic/flying-saucer-users/KuwPoTjaQYU
Steps:
Check out the next repository https://github.com/osnard/flyingsaucer
Analyse the file ITextOutputDevice.java, method processLink(RenderingContext c, Box box)
Make changes based on your needs
Build the project and use the jar file generated
Here the code to create an embedded file based on base64 content.
Java
...String doEmbedFile = handler.getAttributeValue( elem, "data-fs-embed-file" );
if ("true".equals(doEmbedFile.toLowerCase())) {
String fileName = new File(uri).getName();
String content = handler.getAttributeValue( elem, "content" );
com.lowagie.text.Rectangle targetArea = checkLinkArea(c, box);
if (targetArea == null) {
return;
}
try {
if (!_attachments.contains(fileName)) {
byte[] fileBytes = Base64.getDecoder().decode(content.getBytes("UTF-8"));
PdfFileSpecification fs = PdfFileSpecification.fileEmbedded(_writer, null, fileName, fileBytes);
fs.addDescription(fileName, true);
_writer.addFileAttachment(fs);
_attachments.add(fileName);
}
targetArea.setBorder(0);
targetArea.setBorderWidth(0);
//This only works on Adobe Acrobat Reader
PdfAction action = PdfAction.javaScript(
"this.exportDataObject({cName:\"" + fileName + "\", nLaunch:2});",
_writer
);...
HTML
<body><div id='div1'><p><a href='test.png' data-fs-embed-file='true' content='iVBORw0KGgoAAAANSUhEU...'>open test.png file</a></p></div><div id='div2'><p><a href='test.pdf' data-fs-embed-file='true' content='JVBERi0xLjUNCiW1tbW1D...'>open test.pdf file</a></p></div><div id='div3'><p><a href='test.txt' data-fs-embed-file='true' content='VEVFRUVFRUVFRVNUIFRYVA=='>open test.txt file</a></p></div></body>
*base64 content truncated
Output
Greetings and I hope it can help others
just open it on new tab, add attribute target="_blank" in your anchor tag
Open attachment
I am creating pdf files from generated html file by using PdfSelect, the problem is that images are not show on the pdf but is generated on the html.
Dim converter As New HtmlToPdf()
' set converter options
converter.Options.PdfPageSize = PdfPageSize.A4
converter.Options.PdfPageOrientation = PdfPageOrientation.Portrait
' create a new pdf document converting an url
Dim doc As SelectPdf.PdfDocument = converter.ConvertUrl(htmlFilePath)
' get image path
Dim imgFile As String = "C:\Users\Stefan\Desktop\Acczone General\statements\leda.jpg"
' save pdf document
doc.Save(pdfFilePath)
' close pdf document
doc.Close()
I tried some coding but it does not work, can someone please help me so that the images show on the pdf?
My html works 100% it is just the pdf, i am using SelectPdf
Use this format:
Dim imgFile As String = "file:///C:\Users\Stefan\Desktop\Acczone General\statements\leda.jpg"
I have an sql statements that selects a table of data that i want to export to excel in the .xls format,
i added this table to a grid view then rendered that grid view to create an html writer and write it on excel file using asp.net.
But i keep having this warning that the file format and extension does not match.
The issue is that the file you are creating is not a genuine Excel file. It's HTML with a .xls extension.
Please, i need to know what is the best way to export these selected data to the xls file without the warning.
I Have also tried exporting from the dataTable directly, but i still get the warning when tying to open the excel.
// these namespaces need to be added to your code behind file
using System.Configuration;
using System.Data.SqlClient;
using System.Data;
namespace MySpot.UserPages
{
public partial class Journal : System.Web.UI.Page
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MySpotDBConnStr"].ConnectionString);
DataTable dt = new DataTable();
// regular page_load from .aspx file
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
}
}
// added a button with ID=btnDownload and double clicked it's onclick event to auto create method
protected void btnDownload_Click(object sender, EventArgs e)
{
string queryStr = "SELECT * from table";
SqlDataAdapter sda = new SqlDataAdapter(queryStr, conn);
sda.Fill(dt);
ExportTableData(dt);
}
// this does all the work to export to excel
public void ExportTableData(DataTable dtdata)
{
string attach = "attachment;filename=journal.xls";
Response.ClearContent();
Response.AddHeader("content-disposition", attach);
Response.ContentType = "application/ms-excel";
if (dtdata != null)
{
foreach (DataColumn dc in dtdata.Columns)
{
Response.Write(dc.ColumnName + "\t");
//sep = ";";
}
Response.Write(System.Environment.NewLine);
foreach (DataRow dr in dtdata.Rows)
{
for (int i = 0; i < dtdata.Columns.Count; i++)
{
Response.Write(dr[i].ToString() + "\t");
}
Response.Write("\n");
}
Response.End();
}
}
}
}
http://blogs.msdn.com/b/vsofficedeveloper/archive/2008/03/11/excel-2007-extension-warning.aspx
The current design does not allow you to open HTML content from a web site in Excel unless the extension of the URL is .HTM/.HTML/.MHT/.MHTML. So ASP pages that return HTML and set the MIME type to something like XLS to try to force the HTML to open in Excel instead of the web browser (as expected) will always get the security alert since the content does not match the MIME type. If you use an HTML MIME type, then the web browser will open the content instead of Excel. So there is no good workaround for this case because of the lack of a special MIME type for HTML/MHTML that is Excel specific. You can add your own MIME type if you control both the web server and the client desktops that need access to it, but otherwise the best option is to use a different file format or alert your users of the warning and tell them to select Yes to the dialog.
I am struggling with this problem of accessing the sound file (mp3) download in isolated storage to be used in Alarm ,
The problem mentioned before
I am getting this error:
BNS Error: The action request's sound uri is invalid
Please help me but remember I am using the sound file for Alarm
Regarding the code it is the same as the link above.
This is download and save code of the sound file :
Public Async Function DownloadFile(url As Uri) As Task(Of Stream)
wc = New WebClient()
AddHandler wc.OpenReadCompleted, AddressOf OpenReadCompleted
AddHandler wc.DownloadProgressChanged, AddressOf DownloadProgress
wc.OpenReadAsync(url)
Dim r As IO.Stream = Await tcs.Task
Return r
End Function
Private Sub OpenReadCompleted(sender As Object, e As OpenReadCompletedEventArgs)
If e.[Error] IsNot Nothing Then
tcs.TrySetException(e.[Error])
ElseIf e.Cancelled Then
tcs.TrySetCanceled()
Else
tcs.TrySetResult(e.Result)
Dim file As IsolatedStorageFile
file = IsolatedStorageFile.GetUserStoreForApplication()
Using Stream As IsolatedStorageFileStream = New IsolatedStorageFileStream("Sound.mp3", System.IO.FileMode.Create, file)
Dim buffer As Byte() = New Byte(1023) {}
While (e.Result.Read(buffer, 0, buffer.Length) > 0)
Stream.Write(buffer, 0, buffer.Length)
End While
End Using
End If
End Sub
Private Sub DownloadProgress(sender As Object, e As DownloadProgressChangedEventArgs)
Proind.Value = e.ProgressPercentage / 100
Proind.Text = e.ProgressPercentage.ToString & " %" & " ( " & (e.BytesReceived \ 1000).ToString & "/" & (e.TotalBytesToReceive \ 1000).ToString & " ) KB"
End Sub
The problem is that you are trying to set a file in the isolated storage as the sound of the alarm, and that's not allowed. Only files packaged in .xap can be set as sound source of the alarm:
Remarks
The Sound URI must point to a file packaged in the application’s .xap
file. Isolated storage is not supported. When the alarm is launched,
the sound is played quietly and then gradually increases in volume.
There is no way to modify this behavior.
From:
Alarm.Sound Property
However, there is a way you could use a downloaded song as alam's sound. In OpenReadCompleted method, instead of saving the downloaded file in the isolated storage, create a file using File.Create method, and store the data there. Then it will be possible to use this file as the alarm sound:
Here is the C# code, I think you will easily translate to VB:
byte[] buffer = new byte[e.Result.Length];
e.Result.Read(buffer, 0, buffer.Length);
using (var fs = File.Create("file.mp3"))
{
fs.Write(buffer, 0, buffer.Length);
}
Then, you can set the Sound property of the alarm as:
alarm.Sound = new Uri("/file.mp3", UriKind.Relative);