Click here to Skip to main content
15,887,175 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello,

I want to Export the SVG Image Created on my web page into Excel.
I am using MVC4 architecture and razor web pages.
Scenario:
I have a grid and a SVG chart in the web page.
I could able to import the chart data into the Excel file.
Please give me suggestions about how to import the SVG chart to Excel?

Thank You,
Sharath
Posted

1 solution

Copy and paste this macro into module through VBA interface:
Sub svgImport()
'
' svgImport Macro
' importing .svg via fixed width text from .svg usg Import dialog in XL
'
' sn.svg is svg file
'
' svgImport.xls is target XL spreadsheet
'
    With ActiveSheet.QueryTables.Add(Connection:= _
        "TEXT;C:\Users\SN\svgImport\sn.svg" _
        , Destination:=Range("$A$1"))
        .Name = "snsvg"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .TextFilePromptOnRefresh = False
        .TextFilePlatform = 437
        .TextFileStartRow = 1
        .TextFileParseType = xlFixedWidth
        .TextFileTextQualifier = xlTextQualifierDoubleQuote
        .TextFileConsecutiveDelimiter = False
        .TextFileTabDelimiter = True
        .TextFileSemicolonDelimiter = False
        .TextFileCommaDelimiter = False
        .TextFileSpaceDelimiter = False
        .TextFileColumnDataTypes = Array(2)
        .TextFileTrailingMinusNumbers = True
        .Refresh BackgroundQuery:=False
    End With
    ChDir "C:\users\sn\svgImport"
    ActiveWorkbook.SaveAs Filename:= _
        "C:\users\sn\svgImport\svgImport.xls", FileFormat:= _
        xlExcel8, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False _
        , CreateBackup:=False
    Columns("A:A").ColumnWidth = 147.6
End Sub

Excel 2007 doesn't interpret .svg, of course, so nothing gets embedded as an image. The fixed-width text nature of the input at runtime does no wrapping so with any luck no truncation will occur. Huge .svg files might be another matter.
 
Share this answer
 
Comments
SharathNaik1990 8-Sep-13 3:14am    
Thank you RedDk,

I want the code in C#. I will try to interpret the same in C# and see how it works.
I will get back to you, if I need some more help on this.

Thank You,
Sharath

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900