4 Replies - 1302 Views - Last Post: 15 January 2013 - 05:32 AM Rate Topic: -----

#1 Xna4life  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 78
  • Joined: 21-February 12

import excel doc, the display in proper format

Posted 15 January 2013 - 04:11 AM

Hey guys,
Just trying to increase my programming ability atm so any help would be much appreciate.

In my asp.net project i've used (aspx)
    <asp:Panel ID="Excel" runat="server">     
    </asp:Panel>



(aspx.cs)
    ExcelFile ef = new ExcelFile();
            string fileName = @"C:\\location of excel doc";
            ef.LoadXlsx(fileName, XlsxOptions.PreserveMakeCopy);
    
            StringBuilder sb = new StringBuilder();
    
            foreach (ExcelWorksheet sheet in ef.Worksheets)
            {
                sb.AppendLine();
                sb.AppendFormat("------{0}--------", sheet.Name);
    
                foreach (ExcelRow row in sheet.Rows)
                {
                    sb.AppendLine();
                    foreach (ExcelCell cell in row.AllocatedCells)
                    {
                        if (cell.Value != null)
                        {
                            Label x = new Label();
                            x.Text = cell.Value.ToString();
                            Excel.Controls.Add(x);
    
                            sb.AppendFormat("{0}({1})", cell.Value, cell.Value.GetType().Name);
                            sb.Append("\t");
                        }
                    }
                }
            }
    
            Console.WriteLine(sb.ToString());


This works fine but it displays the excel file as a big lump of text clumped together, I would appreciate it if someone could give me a tip or somewhere to get started on how to display the output in a nice table

thank you

Is This A Good Question/Topic? 0
  • +

Replies To: import excel doc, the display in proper format

#2 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3517
  • View blog
  • Posts: 12,009
  • Joined: 12-December 12

Re: import excel doc, the display in proper format

Posted 15 January 2013 - 04:37 AM

Instead of

sb.AppendLine();

try:

sb.Append(Environment.NewLine);

I understand they are supposed to be the same but, apparently, not always!
Was This Post Helpful? 0
  • +
  • -

#3 Xna4life  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 78
  • Joined: 21-February 12

Re: import excel doc, the display in proper format

Posted 15 January 2013 - 04:41 AM

thank you for the help but this has not helped, any other suggestions?
Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3517
  • View blog
  • Posts: 12,009
  • Joined: 12-December 12

Re: import excel doc, the display in proper format

Posted 15 January 2013 - 04:54 AM

View PostXna4life, on 15 January 2013 - 04:41 AM, said:

thank you for the help but this has not helped, any other suggestions?


Did you try this for both sb.AppendLine() statements that you have?

Otherwise, you could try adding sb.Append('\n') at the bottom of your foreach-row loop.

This post has been edited by andrewsw: 15 January 2013 - 04:54 AM

Was This Post Helpful? 0
  • +
  • -

#5 Xna4life  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 78
  • Joined: 21-February 12

Re: import excel doc, the display in proper format

Posted 15 January 2013 - 05:32 AM

Again, thank you for the reply but neither has worked, any more suggestions?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1