locked
how to open a client side excel file on the server, C# RRS feed

  • Question

  • User-387519392 posted

    Hi all,

    I want to open an Excel file, use the ApplicationClass,Workbook and Worksheet classes.which I published the solution on the server , my code open the excel workbook on the server machine. on the client machine, the user login the web site and start up the excel application web page,can choose open which excel file on the client machine.I want to open the workbook on the web page. How can I do that? how can i give the path? from server side to open client side excel file.

     Below is the relative code

    protected void getExcelCols(string path, int page)

    {

    ApplicationClass app = new ApplicationClass();

    Workbook book = null;

    Worksheet sheet = null;

    try

    {

    app.Visible =
    false;

    app.ScreenUpdating = false;

    app.DisplayAlerts = false;

     

    book = app.Workbooks.Open(
    @"" + path + "", Missing.Value, Missing.Value, Missing.Value

    , Missing.Value, Missing.Value, Missing.Value, Missing.Value

    , Missing.Value, Missing.Value, Missing.Value, Missing.Value

    , Missing.Value, Missing.Value, Missing.Value);

    sheet = (Worksheet)book.Worksheets[page];

     

    int rowCount = sheet.UsedRange.Rows.Count;

    ViewState["TotalRecords"] = rowCount;

    int colCount = sheet.UsedRange.Columns.Count;

    object[,] values = (object[,])sheet.UsedRange.Value2;

    //add dropdownlist values

    lbxIFields.Items.Clear();

    if (GetUserParameters.OptionFirst)

    {

    for (int i = 0; i < colCount; i++)

    {

    lbxIFields.Items.Insert(i, values[1, i + 1].ToString());

    }

    }

    else

    {

    string[] cha = new string[26] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" };for (int i = 0; i < colCount; i++)

    {

    lbxIFields.Items.Insert(i,
    "Column " + cha[i].ToString());

    }

    }

    }

    catch (Exception e)

    {

    e.Message.ToString();

    UIGCommons.ShowMessage("Import Users", e.Message.ToString());

    }

    finally

    {

    sheet =
    null;

    if (book != null)

    book.Close(false, Missing.Value, Missing.Value);

    book = null;

    if (app != null)

    app.Quit();

    app =
    null;

    }

    }

     

     

    Thanks in advance! 

    Thursday, May 28, 2009 11:09 AM

All replies

  • User-387519392 posted

    choose another solution, first upload excel file to the server, then open the file in the server, after used then delete that file.

    Friday, June 5, 2009 3:47 PM