Note that there are some explanatory texts on larger screens.

plurals
  1. POTrying to understand C# and XML Spreadsheets in ASP.net
    primarykey
    data
    text
    <p>I'm currently building a web application that will give users the same information they see on a table on the current page, in Excel spreadsheet format. I found some previous code in another project that did the same thing.</p> <p>Small question first: Does anyone know how the Column ss:Width works? It's not an exact match. <code>Column ss:AutoFitWidth="0" ss:Width="114"</code> returns a column width of 21.00...</p> <p>Where I'm having most of my trouble is, all of the data that is passed into the spreadsheet has leading and tailing whitespace; I have no idea how to remove it. I've tried <code>.Trim()</code> when I make my <code>.ToString()</code> query and I've been looking into other methods, but I haven't seemed to find it. The following is a snippet of my worksheet code:</p> <pre><code> &lt;Worksheet ss:Name="UserMgmt1"&gt; &lt;Table&gt; @*Name*@ &lt;Column ss:AutoFitWidth="0" ss:Width="114" /&gt; &lt;Row&gt; &lt;Cell ss:StyleID="s29"&gt; &lt;Data ss:Type="String"&gt;Name&lt;/Data&gt; &lt;/Cell&gt; &lt;/Row&gt; @foreach (tbl_Users query in ViewBag.contents ) { &lt;Row&gt; &lt;Cell ss:StyleID="s31"&gt; &lt;ss:Data ss:Type="String" &gt; @(query.Name.ToString().Trim()) &lt;/ss:Data&gt; &lt;/Cell&gt; &lt;/Row&gt; } &lt;/Table&gt; &lt;/Worksheet&gt; </code></pre> <p></p> <p>Forgot to add the ActionResult that implements this code:</p> <pre><code> public ActionResult _Excel(tblUsers model) { List&lt;tbl_Users&gt; inquiriesList = UserManageModel.GetResults(model); ViewBag.contents = inquiriesList; return View("_Excel"); } </code></pre> <p>And the call:</p> <pre><code>@using (Html.BeginForm("_Excel", "UserManage", FormMethod.Post)) { &lt;input type="submit" value="View Detailed List of Users in Excel" /&gt; } </code></pre> <p>The result looks like this in Excel, with that much whitespace surrounding each string item:</p> <pre><code> Administrator </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload