Search Results for

    Show / Hide Table of Contents

    Using the FlexCel ASP viewer component (VB.Net / netframework)

    Note

    This demo is available in your FlexCel installation at <FlexCel Install Folder>\samples\vb\VS2022\netframework\25.Printing and Exporting\50.ASP.NET HTML Viewer and also at https:​//​github.​com/​tmssoftware/​TMS-​FlexCel.​NET-​demos/​tree/​master/​vb/​VS2022/​netframework/​Modules/​25.​Printing and Exporting/50.ASP.NET HTML Viewer

    Overview

    A simple example on how to use the component FlexCelAspViewer to display xls files as html in a web browser.

    Note

    This demo does not run from MainDemo and it needs **.NET 2.0 or newer.

    In order to run this demo, open the website from Visual Studio 2005 or newer, by doing: Menu->File->Open->Website

    and pointing to the Modules\25.Printing and Exporting\50.ASP.NET HTML Viewer folder.

    Concepts

    • In this demo we will use .TemporaryFiles to create the images. This will create all images as GUIDs in the "images" folder. Images older than 15 minutes will be deleted when a new page is requested, and there is an "overflow guard" that prevents having more than 5000 images in the images folder.

    • If you wanted to use HttpHandlers to return the images, you would need to add the following lines to web.config:

        <httpHandlers>
        <add verb="*" path="flexcelviewer.ashx"
          type="FlexCel.AspNet.UniqueTemporaryFilesImageHandler,FlexCel.AspNet"/>
        </httpHandlers>
      

    This has already been done in the example, so you just need to switch the image mode to use UniqueTemporaryFiles.

    • In order to delete the temporary images once the timeout has happened, we use ImageTimeout and MaxTemporaryImages. Make sure you have rights to delete images in the image folders for this to work. You could also manually delete the images with a script on the server.

    • FlexCelAspViewer is great for small sites, but due to the way it handles images, (make sure you read the [

      ) it might not scale enough if you do not provide a custom image handler. ](~/guides/html-exporting-guide.md# -----it-might-not-scale-enough-if-you-do-not-provide --a-custom-image-handler )

    Files

    Default.aspx.vb

    Imports System
    Imports System.Data
    Imports System.Configuration
    Imports System.Web
    Imports System.Web.Security
    Imports System.Web.UI
    Imports System.Web.UI.WebControls
    Imports System.Web.UI.WebControls.WebParts
    Imports System.Web.UI.HtmlControls
    
    Imports FlexCel.Core
    Imports FlexCel.XlsAdapter
    Imports FlexCel.Render
    Imports FlexCel.AspNet
    
    Partial Public Class _Default
        Inherits System.Web.UI.Page
    
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
            Dim xls As New XlsFile()
    
            Dim DefaultFile As String = Server.MapPath("~/default.xls")
            If IsPostBack Then
                If Uploader.HasFile Then
                    xls.Open(Uploader.FileContent)
                Else
                    xls.Open(DefaultFile)
                End If
            Else
                xls.Open(DefaultFile)
            End If
    
            Viewer.HtmlExport.ImageNaming = TImageNaming.Guid
            Viewer.HtmlExport.Workbook = xls
            Viewer.RelativeImagePath = "images"
            Viewer.HtmlExport.FixIE6TransparentPngSupport = True 'This is only needed if you are using IE and there are transparent png files.
            Viewer.ImageExportMode = TImageExportMode.TemporaryFiles
    
        End Sub
    End Class
    
    In This Article
    Back to top FlexCel Studio for the .NET Framework v7.24.0.0
    © 2002 - 2025 tmssoftware.com