Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6215131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:59:57+00:00 2026-05-24T06:59:57+00:00

This one should be simple, but I don’t really know how to find a

  • 0

This one should be simple, but I don’t really know how to find a way to do it…

I am using .NET 4.0. I have an object[12] filled with decimal numbers, and want to use it to fill an Excel range of Doubles [1,12]. I am converting JSON using JavaScriptSerializer:

JavaScriptSerializer javascriptSerializer = new JavaScriptSerializer();
var jsonData = javascriptSerializer.Deserialize<dynamic>("{data:[0.11, 0.12, 0.13, 0.14, 0.15, 0.16, 0.17, 0.18, 0.19, 0.2, 0.21, 0.22]}");

It should be a one-liner, but the only working thing I can come up with is:

var myArray = new Double[1, 12];
// the cast to Double is necessary as json data is of type decimal, however excel seems to only accepts Double here
for (int i = 0; i < 12; i++) { PrimeShr[0,i] = (Double) jsonData["data"][i]; };
// sheet is of type Microsoft.Office.Interop.Excel.Worksheet
sheet.Range["myExcelRangeName"].Value2 = myArray;

or still rather pitiful, but at least in one line:

sheet.Range["Input_PremiumSHR"].Value2 = new Double[1, 12] { { (Double)jsonData["data"][0], (Double)jsonData["data"][1], (Double)jsonData["data"][2], (Double)jsonData["data"][3], (Double)jsonData["data"][4], (Double)jsonData["data"][5], (Double)jsonData["data"][6], (Double)jsonData["data"][7], (Double)jsonData["data"][8], (Double)jsonData["data"][9], (Double)jsonData["data"][10], (Double)jsonData["data"][11] } };

I’d expect something like that to work, but from what I gather initializers won’t work this way :

sheet.Range["Input_PremiumSHR"].Value2 = new Double[1, 12] { new System.Collections.ArrayList( jsonData["data"] ).ToArray() };

I have quite a few similar cases (one with [12,1] which probably could be harder) and I don’t want to struggle with each one that much. Is there a way to write it a bit more simpler?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T06:59:57+00:00Added an answer on May 24, 2026 at 6:59 am

    You can create an extension method that turns a single-dimensional array (or any other collection) into a 2D array with one column:

    static T[,] ToColumn<T>(this IEnumerable<T> sequence)
    {
        var items = sequence.ToArray();
    
        var column = new T[1, items.Length];
    
        for (int i = 0; i < items.Length; i++)
            column[0, i] = items[i];
    
        return column;
    }
    

    Using that you can write the code like this:

    var data = (object[])jsonData["data"];
    
    var column = data.Cast<decimal>().Select(x => (double)x).ToColumn();
    
    sheet.Range["myExcelRangeName"].Value2 = column;
    

    You could write that on one line, but I think that would hurt readability.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this should be simple and I should know it but it's eluding
This should hopefully be a simple one. I would like to add an extension
Good afternoon, This should be an easy one. I've done the cookie-cutter default ASP.NET
This should be simple. Question How do you get a pointcut in one project
In this thread some one commented that the following code should only be used
Has any one done this before? It would seem to me that there should
This one has been bugging me for a while now. Is there a way
My question is similar to this one but I'm having some problems with the
I have some question about using queues and threads. I already made researches, but
This one will take some explaining. What I've done is create a specific custom

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.