2
$\begingroup$

I have a generated a dataset, name TRES. Its a data between wavelength vs intensity for different time. time varies from 0 ns to 5ns with an interval of 0.1ns. So there is a 51 no of set, and I want to export it in xlsx format. I have used the code:

TRESdata = {
  {{
    0., 0.0310218, 0.0323585, 0.0333725, 0.0337619, 0.0326912, 
    0.0315401, 0.0267583, 0.0223457, 0.0174552, 0.0130177, 0.00917527, 
    0.0071019, 0.00502596, 0.00212264, 0.000176303
  }},
  {{
    0., 0.0308938, 0.0322531, 0.0332925, 0.033701, 0.0326509, 0.0315132, 
    0.026754, 0.0223486, 0.0174704, 0.0130417, 0.00920224, 0.00712387, 
    0.00504376, 0.00213247, 0.000177189
  }}, 
  {{
    0., 0.0303927, 0.03184, 0.0329782, 0.0334615, 0.0324919, 0.0314067, 
    0.0267366, 0.0223598, 0.0175299, 0.0131354, 0.00930758, 0.00720961, 
    0.00511313, 0.00217079, 0.000180641
  }}
};
Export["TRESdata.xlsx", TRESdata]

In this process all datas are exported and when I open it via excel, then it opens. For each time, it creates a excel sheet. Its fine, but I have to assign the name of each sheet as "0ns","0.1ns","0.2ns" and so on instead of "sheet1","sheet2" etc. I can assign the name of sheet if there is 2-3 no of data using

Export[
  "TRESdata.xlsx",
  {
    "0ns" -> TRESdata[[1]],
    "0.1ns" -> TRESdata[[2]],
    "0.2ns" -> TRESdata[[3]]
  }
]

but how can I set the name of each sheet automatically for such a big data set?

$\endgroup$
  • $\begingroup$ Can you add a minimal working example of your current code to your question? $\endgroup$ – Lukas Lang Apr 12 at 10:32
  • $\begingroup$ TRESdata={{0., 0.0310218, 0.0323585, 0.0333725, 0.0337619, 0.0326912, \ 0.0315401, 0.0267583, 0.0223457, 0.0174552, 0.0130177, 0.00917527, \ 0.0071019, 0.00502596, 0.00212264, 0.000176303}, {0., 0.0308938, \ 0.0322531, 0.0332925, 0.033701, 0.0326509, 0.0315132, 0.026754, \ 0.0223486, 0.0174704, 0.0130417, 0.00920224, 0.00712387, 0.00504376, \ 0.00213247, 0.000177189},{0., 0.0303927, 0.03184, 0.0329782, 0.0334615, 0.0324919, 0.0314067, 0.0267366, 0.0223598, 0.0175299, 0.0131354, 0.00930758, 0.00720961, 0.00511313, 0.00217079, 0.000180641}} $\endgroup$ – P Pyne Apr 12 at 10:35
  • $\begingroup$ This is some of the data which I have pasted from mathematica. I can assign the name of the as follows :Export["testTREStest.xls", {"0ns" -> TRESdata1, "0.05ns" -> TRESdata2}],but how can I assign the names for huge no of sheets? $\endgroup$ – P Pyne Apr 12 at 10:36
  • $\begingroup$ Thank you. Note: You can use the "Edit" button to edit the content of your question. This way the code is more easily readable (be sure to use the appropriate formatting) and more visble to other users. $\endgroup$ – Lukas Lang Apr 12 at 10:39
  • $\begingroup$ I've added your code (slightly edited) to the main question and rephrased it slightly - feel free to correct it if I made any mistakes $\endgroup$ – Lukas Lang Apr 12 at 10:54
2
$\begingroup$

You can create the list of sheet names using e.g. StringTemplate, and use Thread to combine the names with the data:

(* generate the names. Note the use of 1/10 instead of 0.1 to avoid names like 0.ns *)
names = StringTemplate["``ns"] /@ Range[0, 2/10, 1/10]
(* {"0ns", "0.1ns", "0.2ns"} *)

(* export the data *)
Export["TRESdata.xlsx", Thread[names -> TRESdata]]
$\endgroup$
  • $\begingroup$ Thank you for your kind help $\endgroup$ – P Pyne Apr 13 at 11:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.