Output ArrayList to excel in jsf

Hi,
I want to show an arraylist (or a string with data if arraylist is not possible) in excel format within my jsf page, but i don't want to save the data to a file first... is this possible?
I've tried to do the following, but the data is not what i wanted...
  public String generateExcelOutput(List list){
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    ObjectOutputStream objectOutputStream;
    try {
      objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
      objectOutputStream.writeObject(list);
    } catch (IOException e) {
       throw new FacesException(e);
    byte[] excelData = byteArrayOutputStream.toByteArray();
    FacesContext faces = FacesContext.getCurrentInstance();
    HttpServletResponse response = (HttpServletResponse) faces.getExternalContext().getResponse();
    response.setContentType("application/vnd.ms-excel");
    response.setContentLength(excelData.length);
    try {
      ServletOutputStream out;
      out = response.getOutputStream();
      out.write(excelData);
    } catch (IOException e) {
      throw new FacesException(e);
    faces.responseComplete();
    return null;
  }--> a popup disappears with the question to save or open...that's correct but i also get a notice that the file is corrupt and the data is not shown as it should be...
Can anyone help me, perhaps with an example...
Thanks!

By using jakarta-poi, output the workbook like this...
HSSFWorkbook generatedExcel = null;
generatedExcel = generateExcel(blah blah);
generatedExcel.write(response.getOutputStream()); If you are trying to export your datatables to excel, use excelcreator
http://sourceforge.net/project/showfiles.php?group_id=137466&package_id=188186

Similar Messages

  • Issue with Varchar2 field conversion for report output generated in EXCEL

    Hello All,
    I have an unique problem with one of my new reports for the User. The user wants the report output generated in excel data only(delimited data) format *(reports builder 10g)* .
    Everything was fine until i encountered this problem, there was this field which has unique ID's(alphanumeric and numeric), when i tried to run the report and generate output in Excel the numeric ID's say for example *(41593497999679354429)* is converted in excel and displayed like *(2.5881E+19)* and after format cells in excel it displays *(41593497999679300000).*
    The issue is only with 20 digits numeric ID's , if i append any special character to the end say '#' or '..' it shows the exact value along with the appended character. But the user insist they need only the value that is in the table. I am finding it hard to figure out, if any one of you have encountered the same issue or if any of you have any suggestions to overcome this excel conversion thing please do advice me.
    Thanks in advance :)

    Thanks for you response, but i already tried what you suggested, instead of appending single quote in front of ID, i did at the end prior with '#', it preserves the value if i add any character to the id but the appended value shows up too :(.
    Well, i just got the solution and it did work, thanks to [Brian Hill|https://forums.oracle.com/forums/thread.jspa?threadID=651632] for the post, i did what exactly he said and it worked. I was so very happy and wanted to share with everyone.

  • How to  send ALV output data into Excel sheet format via Mail to the user?

    Hi friends,
    I have a doubt ie,
    How to  send ALV output data into Excel sheet format via Mail to the user?
    regards
    Moosa

    Hi,
    Provide the output internal table to the objbin in the below FM
    Send Message
      CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
           EXPORTING
                document_data              = i_docdata
                put_in_outbox              = c_x
           TABLES
                packing_list               = i_objpack
                object_header              = i_objhead
                contents_bin               = i_objbin
                contents_txt               = i_objtxt
                receivers                  = i_reclist
    and specify the document type
      i_objpack-doc_type   = 'XLS'.
    and try.
    Regards,
    Nandha

  • ALV Grid to be run in background & to generate output file in Excel format

    I use  REUSE_ALV_GRID_DISPLAY in my program for the ALV output
    My Requirement is Program to be run in a background since it is getting timed out when executed in foreground and also to generate the output file in Excel format. And we are using 4.6 C version.
    how do i attain this?

    Hello,
    One alternate solution can be :
    Execute your report in background and then send the data to Spool .
    From this spool , you can download the data in excel file.
              SUBMIT xyz TO SAP-SPOOL
                 SPOOL PARAMETERS gt_print_parameters.
    Regards,
    Sandeep

  • Output to an excel sheet

    Hi all,
    How do we send the 1)script output 2)ALV report output to an excel sheet
    please expedite
    thanks

    Hi arun,
    Check the below example, to download the ALV report output to an excel sheet.
    REPORT Z_CONCEPTALV .
    TABLES: KNA1,VBAK.
    DATA: ITAB TYPE TABLE OF VBAK,
          CONTAINER TYPE SCRFNAME VALUE 'ALVCONTROL',
          CUST TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
          GRID TYPE REF TO CL_GUI_ALV_GRID,
          L_CONTAINER TYPE SCRFNAME VALUE 'LOGO',
          I_PARENT TYPE REF TO CL_GUI_CONTAINER,
          L_CUST TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
          TREE TYPE REF TO CL_GUI_ALV_TREE_SIMPLE,
          LT_LIST_COMMENTARY TYPE SLIS_T_LISTHEADER,
          L_LOGO TYPE SDYDO_VALUE.
    DATA: OK_CODE(4).
    CALL SCREEN 1100.
    *&      Module  STATUS_1100  OUTPUT
          text
    MODULE STATUS_1100 OUTPUT.
    SET PF-STATUS 'xxxxxxxx'.
    SET TITLEBAR 'xxx'.
    CASE OK_CODE.
    WHEN 'DISP'.
    SELECT * FROM VBAK INTO TABLE ITAB WHERE KUNNR = KNA1-KUNNR.
    IF CUST IS INITIAL.
    CREATE OBJECT CUST EXPORTING CONTAINER_NAME = CONTAINER.
    CREATE OBJECT GRID EXPORTING I_PARENT = CUST.
    CALL METHOD GRID->SET_TABLE_FOR_FIRST_DISPLAY EXPORTING I_STRUCTURE_NAME
    = 'VBAK' CHANGING IT_OUTTAB = ITAB.
    ENDIF.
    IF L_CUST IS INITIAL.
    CREATE OBJECT L_CUST EXPORTING CONTAINER_NAME = L_CONTAINER.
    CREATE OBJECT TREE EXPORTING I_PARENT = L_CUST.
    PERFORM BUILD_COMMENT USING LT_LIST_COMMENTARY.
    CALL METHOD TREE->CREATE_REPORT_HEADER EXPORTING IT_LIST_COMMENTARY =
    LT_LIST_COMMENTARY I_LOGO = L_LOGO.
    ENDIF.
    WHEN 'DOWN'.
    PERFORM F_DOWNLOAD_TO_EXCEL.
    WHEN 'EXIT'.
    LEAVE PROGRAM.
    ENDCASE.
    ENDMODULE.                 " STATUS_1100  OUTPUT
    FORM BUILD_COMMENT USING LT_LIST_COMMENTARY.
    L_LOGO = 'ENJOYSAP_LOGO'.
    ENDFORM.
    FORM F_DOWNLOAD_TO_EXCEL.
    CALL FUNCTION 'DOWNLOAD'
    EXPORTING
      BIN_FILESIZE                  = ' '
      CODEPAGE                      = ' '
       FILENAME                       = ' '
       FILETYPE                       = 'DAT'
      ITEM                          = ' '
      MODE                          = ' '
      WK1_N_FORMAT                  = ' '
      WK1_N_SIZE                    = ' '
      WK1_T_FORMAT                  = ' '
      WK1_T_SIZE                    = ' '
      FILEMASK_MASK                 = ' '
      FILEMASK_TEXT                 = ' '
      FILETYPE_NO_CHANGE            = ' '
      FILEMASK_ALL                  = ' '
      FILETYPE_NO_SHOW              = ' '
      SILENT                        = 'S'
      COL_SELECT                    = ' '
      COL_SELECTMASK                = ' '
      NO_AUTH_CHECK                 = ' '
    IMPORTING
      ACT_FILENAME                  =
      ACT_FILETYPE                  =
      FILESIZE                      =
      CANCEL                        =
      TABLES
        DATA_TAB                      = ITAB
      FIELDNAMES                    =
    EXCEPTIONS
      INVALID_FILESIZE              = 1
      INVALID_TABLE_WIDTH           = 2
      INVALID_TYPE                  = 3
      NO_BATCH                      = 4
      UNKNOWN_ERROR                 = 5
      GUI_REFUSE_FILETRANSFER       = 6
      CUSTOMER_ERROR                = 7
      OTHERS                        = 8
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    ENDFORM.

  • CSV output (export to excel) don't use right code table

    CSV output (export to excel) don't use right code table. We use code table
    8859-2 (reports and forms are OK). Why export to excel don't use this code table.
    Thanks for answers

    You could also take the example from my blob that Denes mentioned and instrument it to output in either CSV or HTML. This way, you could have a single procedure that worked for both formats.
    All you would need to do is handle each field differently - pad a TD and /TD (with proper brackets, of course) if its HTML or just append a comma if it's CSV.
    Thanks,
    &#150; Scott &#150;
    http://spendolini.blogspot.com/
    http://sumnertech.com/

  • Query output transfer to excel file

    hi all,
    how can i query output transfer to excel file ? i am not using any tool. please suggest me. is there any method that i transfer that output to excel file?

    You can create a csv file. See dump_csv function from Tom Kyte.

  • Reg. ALV output transported into Excel

    Dear All,
                   when i transported my ALV report output to excel file , amount column is suppressed from decimal places .
    i.e. in excel file ,  decimal values of amount column is not shown in some amounts.
    Please provide some inputs
    Thanks & Regards
    shailesh

    Hi ,
    Check this [LINK|ALV List output to Excel file; for  ALV output transported into Excel.
    hope it will help you .
    Regards,
    Saravana.S

  • Download specific output fields to excel

    Hi All,
    We have a report program that downloads an excel file having about 60 output fields. The program has no ALV output.
    Everytime we do not require these 60 fields to be shown in output excel. we need specific output fields in excel and those specific fields could be dynamic.
    Is there any way to download specific output fields in excel as we do in ALV variant.
    In alv,  we can achieve this through a layout variant in selection screen and download the alv output in excel. But we dont require alv to download excel from there.
    Thanks,
    Srilakshmi.

    Hi
    Something like this:
    DATA: BEGIN OF t_layout OCCURS 0,
            mark      TYPE c,
            fieldname LIKE dd03l-fieldname,
          END  OF t_layout.
    TYPE-POOLS slis.
    DATA: gt_fieldcat TYPE  slis_t_fieldcat_alv WITH HEADER LINE.
    DATA: lt_report TYPE sy-repid.
    DO 60 TIMES.
      t_layout-fieldname = 'Field'.
      MOVE sy-index TO t_layout-fieldname+6.
      APPEND t_layout.
    ENDDO.
    lt_report = sy-repid.
    CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
      EXPORTING
        i_program_name     = lt_report
        i_internal_tabname = 'T_LAYOUT'
        i_inclname         = lt_report
      CHANGING
        ct_fieldcat        = gt_fieldcat[].
    CALL FUNCTION 'REUSE_ALV_POPUP_TO_SELECT'
      EXPORTING
        i_title              = 'Field List'
        i_zebra              = 'X'
        i_checkbox_fieldname = 'MARK'
        i_tabname            = 'T_LAYOUT'
        it_fieldcat          = gt_fieldcat[]
      TABLES
        t_outtab             = t_layout.
    LOOP AT t_layout WHERE mark = 'X'.
      WRITE: / t_layout-fieldname.
    ENDLOOP.
    Max

  • Not able to generate output in CSV(EXCEL) format

    Hi,
    XML Publisher report is giving me an error when the Preview Format is 'EXCEL'. When I keep the Preview Format as 'PDF', the concurrent program is running successfully and the PDF output is getting generated. But for EXCEL outputs, I am getting the following error :
    The XML page cannot be displayed
    Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.
    The operation completed successfully. Error processing resource 'http://erpap01:8010/OA_CGI/FNDWRR.exe?temp_id=1...
    <td valign="top" class="c7"><p class="c8"><span class="c9">13 July 2009  13:15:57 PM</span>...
    I have using the following Data Template for Data Definition
    <?xml version="1.0" encoding="UTF-8"?>
    <dataTemplate name="EMPDT" description="Employee Details" version="1.0">
    <parameters>
    <parameter dataType="character" name="p_DeptNo"> </parameter>
    </parameters>
    <dataQuery>
    <sqlStatement name="Q1">
    <![CDATA[SELECT EMPNO
                       ,ENAME
                       ,JOB
                       ,MGR
                       ,HIREDATE
                       ,DEPTNO
                       ,SAL
                       ,COMM
                 FROM scott.Emp
              WHERE deptno = NVL(:p_DeptNo,deptno)
         ]]>
    </sqlStatement>
    </dataQuery>
    <dataStructure>
    <group name="G_EMP" dataType="varchar2" source="Q1">
    <element name="EMPNO" value="EMPNO"/>
    <element name="ENAME" value="ENAME"/>
    <element name="JOB" value="JOB"/>
    <element name="MGR" value="MGR"/>
    <element name="HIREDATE" value="HIREDATE"/>
    <element name="DEPTNO" value="DEPTNO"/>
    <element name="SAL" value="SAL"/>
    <element name="COMM" value="COMM"/>
    </group>
    </dataStructure>
    </dataTemplate>
    When I click on Diagnostic - View XML, copy the XML file and generate report using Word plugin, I am able to generate output in PDF and in EXCEL. But for some reason, when I try to run the XML Publisher report using concurrent program, I am unable to generate output in EXCEL and I am getting the error as listed above.
    When I click on View Template - Preview, keeping the Preview format as Excel, I get the following error :
    Exception Detail
    java.lang.reflect.InvocationTargetException
    at sun.reflect.GeneratedMethodAccessor179.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:324)
    at oracle.apps.xdo.common.xml.XSLT10gR1.invokeParse(XSLT10gR1.java:517)
    at oracle.apps.xdo.common.xml.XSLT10gR1.transform(XSLT10gR1.java:224)
    at oracle.apps.xdo.common.xml.XSLTWrapper.transform(XSLTWrapper.java:177)
    at oracle.apps.xdo.template.fo.util.FOUtility.generateFO(FOUtility.java:1044)
    at oracle.apps.xdo.template.fo.util.FOUtility.generateFO(FOUtility.java:997)
    at oracle.apps.xdo.template.fo.util.FOUtility.generateFO(FOUtility.java:212)
    at oracle.apps.xdo.template.FOProcessor.createFO(FOProcessor.java:1657)
    at oracle.apps.xdo.template.FOProcessor.generate(FOProcessor.java:967)
    at oracle.apps.xdo.oa.schema.server.TemplateHelper.runProcessTemplate(TemplateHelper.java:5888)
    at oracle.apps.xdo.oa.schema.server.TemplateHelper.processTemplate(TemplateHelper.java:3438)
    at oracle.apps.xdo.oa.schema.server.TemplateHelper.processTemplate(TemplateHelper.java:3527)
    at oracle.apps.xdo.oa.template.server.TemplatesAMImpl.processTemplate(TemplatesAMImpl.java:2130)
    at sun.reflect.GeneratedMethodAccessor173.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:324)
    at oracle.apps.fnd.framework.server.OAUtility.invokeMethod(OAUtility.java:190)
    at oracle.apps.fnd.framework.server.OAUtility.invokeMethod(OAUtility.java:153)
    at oracle.apps.fnd.framework.server.OAApplicationModuleImpl.invokeMethod(OAApplicationModuleImpl.java:749)
    at oracle.apps.xdo.oa.template.webui.TemplateGeneralCO.previewTemplate(TemplateGeneralCO.java:741)
    at oracle.apps.xdo.oa.template.webui.TemplateGeneralCO.processRequest(TemplateGeneralCO.java:158)
    at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processRequest(OAWebBeanHelper.java:587)
    at oracle.apps.fnd.framework.webui.OAWebBeanContainerHelper.processRequest(OAWebBeanContainerHelper.java:247)
    at oracle.apps.fnd.framework.webui.OAPageLayoutHelper.processRequest(OAPageLayoutHelper.java:1136)
    at oracle.apps.fnd.framework.webui.beans.layout.OAPageLayoutBean.processRequest(OAPageLayoutBean.java:1569)
    at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processRequestChildren(OAWebBeanHelper.java:959)
    at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processRequestChildren(OAWebBeanHelper.java:926)
    at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processRequest(OAWebBeanHelper.java:646)
    at oracle.apps.fnd.framework.webui.OAWebBeanContainerHelper.processRequest(OAWebBeanContainerHelper.java:247)
    at oracle.apps.fnd.framework.webui.beans.form.OAFormBean.processRequest(OAFormBean.java:385)
    at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processRequestChildren(OAWebBeanHelper.java:959)
    at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processRequestChildren(OAWebBeanHelper.java:926)
    at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processRequest(OAWebBeanHelper.java:646)
    at oracle.apps.fnd.framework.webui.OAWebBeanContainerHelper.processRequest(OAWebBeanContainerHelper.java:247)
    at oracle.apps.fnd.framework.webui.beans.OABodyBean.processRequest(OABodyBean.java:353)
    at oracle.apps.fnd.framework.webui.OAPageBean.processRequest(OAPageBean.java:2335)
    at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(OAPageBean.java:1734)
    at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(OAPageBean.java:508)
    at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(OAPageBean.java:429)
    at oa_html._OA._jspService(_OA.java:85)
    at oracle.jsp.runtime.HttpJsp.service(HttpJsp.java:119)
    at oracle.jsp.app.JspApplication.dispatchRequest(JspApplication.java:417)
    at oracle.jsp.JspServlet.doDispatch(JspServlet.java:267)
    at oracle.jsp.JspServlet.internalService(JspServlet.java:186)
    at oracle.jsp.JspServlet.service(JspServlet.java:156)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:588)
    at oracle.jsp.provider.Jsp20RequestDispatcher.forward(Jsp20RequestDispatcher.java:162)
    at oracle.jsp.runtime.OraclePageContext.forward(OraclePageContext.java:187)
    at oa_html._OA._jspService(_OA.java:95)
    at oracle.jsp.runtime.HttpJsp.service(HttpJsp.java:119)
    at oracle.jsp.app.JspApplication.dispatchRequest(JspApplication.java:417)
    at oracle.jsp.JspServlet.doDispatch(JspServlet.java:267)
    at oracle.jsp.JspServlet.internalService(JspServlet.java:186)
    at oracle.jsp.JspServlet.service(JspServlet.java:156)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:588)
    at org.apache.jserv.JServConnection.processRequest(JServConnection.java:456)
    at org.apache.jserv.JServConnection.run(JServConnection.java:294)
    at java.lang.Thread.run(Thread.java:534)
    Caused by: oracle.xdo.parser.v2.XMLParseException: Start of root element expected.
    at oracle.xdo.parser.v2.XMLError.flushErrors1(XMLError.java:324)
    at oracle.xdo.parser.v2.NonValidatingParser.parseRootElement(NonValidatingParser.java:319)
    at oracle.xdo.parser.v2.NonValidatingParser.parseDocument(NonValidatingParser.java:281)
    at oracle.xdo.parser.v2.XMLParser.parse(XMLParser.java:266)
    Any inputs would be appreciated
    Regards
    David

    May be it is browser problem? use another browser like Firefox
    Edited by: ranalawa on Jul 14, 2009 2:21 PM

  • Alv output download to excel sheet spliting into three line

    hi,
    i have developed alv report with 62 fields (62 colums).when i download this output into excel sheet each line spliting into three line.each field has 20 char length.i want download each row as single line.
    i am using local file  (ctrl + shift+F9) -> spreadsheet option
    please advice me to solve this issue. i am using fm REUSE_ALV_GRID_DISPLAY.
    In layout i am using
      DATA:   min_linesize like sy-linsz,   " if initial min_linesize = 80
              max_linesize like sy-linsz.   " Default 250
      min_linesize = 100.
      max_linesize = 1000.
      gt_layout-zebra             = 'X'. "space.
      gt_layout-colwidth_optimize = space.
      gt_layout-max_linesize = min_linesize.
      gt_layout-max_linesize = max_linesize.
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
           i_bypassing_buffer = ' '
           i_callback_program       = sy-repid
           i_callback_pf_status_set = 'SET-PF-STATUS'
           i_callback_user_command  = 'USER_COMMAND'
           it_fieldcat              = gt_fieldcat[]
           it_events                = gt_events[]
           is_layout                = gt_layout
          is_variant               = v_stru_disvar
          i_default                = 'X'
          i_save                   = 'A'
    IMPORTING
      E_EXIT_CAUSED_BY_CALLER           =
      ES_EXIT_CAUSED_BY_USER            =
         TABLES
           t_outtab                          = it_final[]
      EXCEPTIONS
        program_error                     = 1
        OTHERS                            = 2
    Edited by: Raja Ram on Aug 4, 2009 12:40 PM

    solved

  • Please assist with modifying this script to read in a list of servers and output results to excel

    Hello,
    I have an excellent script written by Brian Wilhite to gather the last logged in user using Powershell.
    http://gallery.technet.microsoft.com/scriptcenter/Get-LastLogon-Determining-283f98ae/view/Discussions#content
    My Powershell Fu is stumbling to modify this script to the following requirements:
    Currently the script must be loaded first into Powershell, then it can be executed.  I would rather edit the script in my Powershell ISE, add the .txt file to the script itself that gives a list of the servers I need to scan.  Then when I
    press Run Script in my ISE it executes.
    I would also like to output the results of the file to excel (.xls or .csv will do).  Currently the results look as follows:
    Computer : SVR01
    User : WILHITE\BRIAN
    SID : S-1-5-21-012345678-0123456789-012345678-012345
    Time : 9/20/2012 1:07:58 PM
    CurrentlyLoggedOn : False
    I would prefer it shows up like so:
    Computer User SID Time Currently LoggedOn
    SVR01 WILHITE\BRIAN S-1xxx 9/20/2012 1:07:58 PM FalseSRV02 WILHITE\BRIAN S-2xxx 9/26/2014 10:00:00 AM True
    Any help you can provide would be greatly appreciated.  I'll add the full script to the end of this post.
    Thank you.
    Function Get-LastLogon
    <#
    .SYNOPSIS
    This function will list the last user logged on or logged in.
    .DESCRIPTION
    This function will list the last user logged on or logged in. It will detect if the user is currently logged on
    via WMI or the Registry, depending on what version of Windows is running on the target. There is some "guess" work
    to determine what Domain the user truly belongs to if run against Vista NON SP1 and below, since the function
    is using the profile name initially to detect the user name. It then compares the profile name and the Security
    Entries (ACE-SDDL) to see if they are equal to determine Domain and if the profile is loaded via the Registry.
    .PARAMETER ComputerName
    A single Computer or an array of computer names. The default is localhost ($env:COMPUTERNAME).
    .PARAMETER FilterSID
    Filters a single SID from the results. For use if there is a service account commonly used.
    .PARAMETER WQLFilter
    Default WQLFilter defined for the Win32_UserProfile query, it is best to leave this alone, unless you know what
    you are doing.
    Default Value = "NOT SID = 'S-1-5-18' AND NOT SID = 'S-1-5-19' AND NOT SID = 'S-1-5-20'"
    .EXAMPLE
    $Servers = Get-Content "C:\ServerList.txt"
    Get-LastLogon -ComputerName $Servers
    This example will return the last logon information from all the servers in the C:\ServerList.txt file.
    Computer : SVR01
    User : WILHITE\BRIAN
    SID : S-1-5-21-012345678-0123456789-012345678-012345
    Time : 9/20/2012 1:07:58 PM
    CurrentlyLoggedOn : False
    Computer : SVR02
    User : WILIHTE\BRIAN
    SID : S-1-5-21-012345678-0123456789-012345678-012345
    Time : 9/20/2012 12:46:48 PM
    CurrentlyLoggedOn : True
    .EXAMPLE
    Get-LastLogon -ComputerName svr01, svr02 -FilterSID S-1-5-21-012345678-0123456789-012345678-012345
    This example will return the last logon information from all the servers in the C:\ServerList.txt file.
    Computer : SVR01
    User : WILHITE\ADMIN
    SID : S-1-5-21-012345678-0123456789-012345678-543210
    Time : 9/20/2012 1:07:58 PM
    CurrentlyLoggedOn : False
    Computer : SVR02
    User : WILIHTE\ADMIN
    SID : S-1-5-21-012345678-0123456789-012345678-543210
    Time : 9/20/2012 12:46:48 PM
    CurrentlyLoggedOn : True
    .LINK
    http://msdn.microsoft.com/en-us/library/windows/desktop/ee886409(v=vs.85).aspx
    http://msdn.microsoft.com/en-us/library/system.security.principal.securityidentifier.aspx
    .NOTES
    Author: Brian C. Wilhite
    Email: [email protected]
    Date: "09/20/2012"
    Updates: Added FilterSID Parameter
    Cleaned Up Code, defined fewer variables when creating PSObjects
    ToDo: Clean up the UserSID Translation, to continue even if the SID is local
    #>
    [CmdletBinding()]
    param(
    [Parameter(Position=0,ValueFromPipeline=$true)]
    [Alias("CN","Computer")]
    [String[]]$ComputerName="$env:COMPUTERNAME",
    [String]$FilterSID,
    [String]$WQLFilter="NOT SID = 'S-1-5-18' AND NOT SID = 'S-1-5-19' AND NOT SID = 'S-1-5-20'"
    Begin
    #Adjusting ErrorActionPreference to stop on all errors
    $TempErrAct = $ErrorActionPreference
    $ErrorActionPreference = "Stop"
    #Exclude Local System, Local Service & Network Service
    }#End Begin Script Block
    Process
    Foreach ($Computer in $ComputerName)
    $Computer = $Computer.ToUpper().Trim()
    Try
    #Querying Windows version to determine how to proceed.
    $Win32OS = Get-WmiObject -Class Win32_OperatingSystem -ComputerName $Computer
    $Build = $Win32OS.BuildNumber
    #Win32_UserProfile exist on Windows Vista and above
    If ($Build -ge 6001)
    If ($FilterSID)
    $WQLFilter = $WQLFilter + " AND NOT SID = `'$FilterSID`'"
    }#End If ($FilterSID)
    $Win32User = Get-WmiObject -Class Win32_UserProfile -Filter $WQLFilter -ComputerName $Computer
    $LastUser = $Win32User | Sort-Object -Property LastUseTime -Descending | Select-Object -First 1
    $Loaded = $LastUser.Loaded
    $Script:Time = ([WMI]'').ConvertToDateTime($LastUser.LastUseTime)
    #Convert SID to Account for friendly display
    $Script:UserSID = New-Object System.Security.Principal.SecurityIdentifier($LastUser.SID)
    $User = $Script:UserSID.Translate([System.Security.Principal.NTAccount])
    }#End If ($Build -ge 6001)
    If ($Build -le 6000)
    If ($Build -eq 2195)
    $SysDrv = $Win32OS.SystemDirectory.ToCharArray()[0] + ":"
    }#End If ($Build -eq 2195)
    Else
    $SysDrv = $Win32OS.SystemDrive
    }#End Else
    $SysDrv = $SysDrv.Replace(":","$")
    $Script:ProfLoc = "\\$Computer\$SysDrv\Documents and Settings"
    $Profiles = Get-ChildItem -Path $Script:ProfLoc
    $Script:NTUserDatLog = $Profiles | ForEach-Object -Process {$_.GetFiles("ntuser.dat.LOG")}
    #Function to grab last profile data, used for allowing -FilterSID to function properly.
    function GetLastProfData ($InstanceNumber)
    $Script:LastProf = ($Script:NTUserDatLog | Sort-Object -Property LastWriteTime -Descending)[$InstanceNumber]
    $Script:UserName = $Script:LastProf.DirectoryName.Replace("$Script:ProfLoc","").Trim("\").ToUpper()
    $Script:Time = $Script:LastProf.LastAccessTime
    #Getting the SID of the user from the file ACE to compare
    $Script:Sddl = $Script:LastProf.GetAccessControl().Sddl
    $Script:Sddl = $Script:Sddl.split("(") | Select-String -Pattern "[0-9]\)$" | Select-Object -First 1
    #Formatting SID, assuming the 6th entry will be the users SID.
    $Script:Sddl = $Script:Sddl.ToString().Split(";")[5].Trim(")")
    #Convert Account to SID to detect if profile is loaded via the remote registry
    $Script:TranSID = New-Object System.Security.Principal.NTAccount($Script:UserName)
    $Script:UserSID = $Script:TranSID.Translate([System.Security.Principal.SecurityIdentifier])
    }#End function GetLastProfData
    GetLastProfData -InstanceNumber 0
    #If the FilterSID equals the UserSID, rerun GetLastProfData and select the next instance
    If ($Script:UserSID -eq $FilterSID)
    GetLastProfData -InstanceNumber 1
    }#End If ($Script:UserSID -eq $FilterSID)
    #If the detected SID via Sddl matches the UserSID, then connect to the registry to detect currently loggedon.
    If ($Script:Sddl -eq $Script:UserSID)
    $Reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]"Users",$Computer)
    $Loaded = $Reg.GetSubKeyNames() -contains $Script:UserSID.Value
    #Convert SID to Account for friendly display
    $Script:UserSID = New-Object System.Security.Principal.SecurityIdentifier($Script:UserSID)
    $User = $Script:UserSID.Translate([System.Security.Principal.NTAccount])
    }#End If ($Script:Sddl -eq $Script:UserSID)
    Else
    $User = $Script:UserName
    $Loaded = "Unknown"
    }#End Else
    }#End If ($Build -le 6000)
    #Creating Custom PSObject For Output
    New-Object -TypeName PSObject -Property @{
    Computer=$Computer
    User=$User
    SID=$Script:UserSID
    Time=$Script:Time
    CurrentlyLoggedOn=$Loaded
    } | Select-Object Computer, User, SID, Time, CurrentlyLoggedOn
    }#End Try
    Catch
    If ($_.Exception.Message -Like "*Some or all identity references could not be translated*")
    Write-Warning "Unable to Translate $Script:UserSID, try filtering the SID `nby using the -FilterSID parameter."
    Write-Warning "It may be that $Script:UserSID is local to $Computer, Unable to translate remote SID"
    Else
    Write-Warning $_
    }#End Catch
    }#End Foreach ($Computer in $ComputerName)
    }#End Process
    End
    #Resetting ErrorActionPref
    $ErrorActionPreference = $TempErrAct
    }#End End
    }# End Function Get-LastLogon

     This should work:
    Get-LastLogon -Computername (Get-content .\Servers.txt) | Export-CSV .\Output.csv -NoTypeInformation
    I just tested it on my test domain and it did the trick.

  • XML publisher output report in excel format

    Hi
    I have created reports using XML Publisher, the default output preview format was PDF. While submitting the program, in the layout, I changed the format to EXCEL,it give me output in Excel. Now I need to send the output report as an attachment through e-mail.For this I have used a UNIX shell script to send the mail using uuencode and mailx commands.
    I have fetched the name of the report from table using the following command.
    SELECT file_name
    FROM FND_CONC_REQ_OUTPUTS
    WHERE FCR.CONCURRENT_REQUEST_ID = p_req_id;
    The name of the report is : XXBG_PO_IFACE_SO_RPT_8556321_1.EXCEL
    Following is the command to send the e-mail.
    (cat $MAIL_BODY; uuencode XXBG_PO_IFACE_SO_RPT_8556321_1.EXCEL XXBG_PO_RPT.xls) | mailx -m -s "$MAIL_SUBJECT" $mail_id
    I am receiving the mail with the attachement, but when i am trying to open the attachement it is throwing an error and nothing is displayed in the excel sheet.
    Note: When I am sending the mail,in similar way, with 'PDF' attachement it is perfectly fine and the attachement is opening correctly.
    Please help me.
    Thanks in advance,
    Madhu kumar

    Hi schavali,
    The error message is as follows
    Microsoft Office Excel cannot access the file "https://xxxxxxx/Inbox/XXBG_PO_RPT.xls.
    There are several possible reasons:
    --The file path doesnot exist.
    --The file is being used by another program.
    --The workbook you are trying to save has the same name as a currently open workbook.
    After throwing the error, it open s a balck excel sheet.
    Hi hsawwan,
    I have gone through the thread. I am able to see the report when I click the output tab on the concurrent request screen.
    But the problem is, when I am sending the output report as an excel attachment then I am facing the problem.
    There might be some problem with uuenocde or mailx command.
    Thanks
    Madhu Kumar.

  • Unable to get the output when i run any jsf page in adf

    Hi,
    I have created one jsf page to access the business components which i had created earlier after that when i drop the another panel splitter into the second facet of the initial panel splitter we created , I was unable to see in the workspace (.jpx) window.can you suggest me on this.
    after done all the steps if I tried to run that page it starts the WLS servier and createda URL but the url is taking long time approx more that two hour and still not getting the required output only the loading window I can see.
    Please suggest me on this.
    Thanks
    Chetan

    Hi,
    the panelSplitter should at least show in the Structure Window. So check if it is there. The runtime issue can be caused by the proxy settings. Go to Tools / Preferences --> Browser and Proxy and add localhost to the list of exclusion
    If you are new to ADF I recommend running a tutorial like this: http://www.oracle.com/webfolder/technetwork/tutorials/obe/jdev/obe11jdev/ps1/ria_application/developriaapplication_long.htm
    Frank

  • Powershell / Scientific Notation Woes / Formatting Output to Live Excel Sheet

    I have a WMI query in a script that dumps machine information to a live excel sheet.
    I find when I query the model # of the machine using (this line of code from the script):
    $Sheet.Cells.Item($count,4) = (Get-WmiObject win32_computersystem -ComputerName $computer).Model
    The output almost always changes into Scientific Notation, because this is a typical model number :   "3500-E52"
    Is there a way to modify the formatting of the:
    $Sheet.Cells.Item($count,4)
    so that Excel uses "text" formatting for that cell?  I know you can change the fonts etc... but have not been lucky in finding a powershell > excel reference
    that explains how to change a cell or column's formatting beyond the basics.
    I have seen recommendations to others to dump the results queries to a CSV first, and then import into Excel (which would allow a manual change of that column's format).  I'm just
    hoping to bypass the extra "hands on" and format more directly to a sheet in Excel.
    If .csv is the best way to go, I'll muddle through it and change the code.
    Any help is greatly appreciated.
    Ben

    $sheet.Cells(1,1).NumberFormat
    = "@"
    ¯\_(ツ)_/¯

Maybe you are looking for

  • Sales org is invalid for Account

    Hi expert's              I am working on CRM2007 . Whenever  I create a Trade Promotion and select Account type  as "Account" and Planning Account as a BP which I have assigned to sales org,I am getting an error "*Sales org is invalid for Account*."

  • When i plug iphone 4 into computer Itunes stalls

    Every time I go to try to put music or apps from my mac to my iPhone4 itunes doesn't work. It'll get a bar on the top saying "backing up iPhone" but it never backs it up. Every time i try to click on something the rainbow waiting mouse comes up and i

  • Combine 2 scripts

    Hi, i am having 2 scripts Script 1 : user creation Script 2 : Table, function ,sp creation I need to combine this into a single which means I need to login as sysdba and execute the Script 1 and with that user details i need to login and execute the

  • What is row format in SAP B1

    What is difference between row format and table format in form setting of SAP B1. What is the use of Row format. Thanks Arpit

  • Safari shutdown unexpectedly and will NOT reopen

    Safari shut down unexpectedly and will not reopen after several tries at logging bout and starting up again etc e tc