Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Excel Export date

    Hello, I am exporting the fields of a ListGrid with the following code:

    Code:
    DSRequest dsRequestProperties = new DSRequest();  
            dsRequestProperties.setExportAs((ExportFormat)EnumUtil.getEnum(ExportFormat.values(), "xls"));  
            dsRequestProperties.setExportDisplay(ExportDisplay.DOWNLOAD);  
            
            grid.exportData(dsRequestProperties);
    But I am having problems with a date field. I get in the excel file:
    10.09.2003 00:00:00

    Is it possible to format that field to display only the date?
    10.09.2003

    #2
    What's the DataSource definition for the field? If you want only the date information, it should be declared type="date". You can then specify the format you want to use right on the field (but it has to be one of the built-in formats, there's no way currently to define a custom format for export, partly due to limitations in Excel).

    Comment


      #3
      Thanks for the answer.

      The field definition in the datasource is indeed of type="date", here is the field definition:

      <field name="f_geb_datum" title="Geb. Datum" type="date" required="true"/>

      The Datasource:

      <DataSource
      ID="schueler"
      serverType="sql"
      tableName="t_schueler"
      >

      And the field "f_geb_datum" is of type "date" in a microsoft sql database.

      I noticed that if I write:
      grid.exportClientData(dsRequestProperties);

      the field is shown correctly (as a date only) , but if I write grid.exportData(csRequestProperties); the 00:00:00 appears.

      The request payload is:
      Code:
      payload: {
          criteria:{
              schultyp:2
          },
          operationConfig:{
              dataSource:"schueler",
              operationType:"fetch",
              textMatchStyle:"exact"
          },
          exportResults:true,
          exportAs:"xls",
          exportDelimiter:",",
          exportTitleSeparatorChar:null,
          exportFilename:"Results.xls",
          exportDisplay:"download",
          lineBreakStyle:"default",
          exportFields:[
              "f_name",
              "f_vorname",
              "f_geb_datum",
              "f_archiviert",
              "f_deleted"
          ],
          sortBy:[
              "f_name"
          ],
          appID:"builtinApplication",
          operation:"schueler_fetch",
          oldValues:{
              schultyp:2
          }
      }
      So how can SmartGWT know which type is expected? The type is not in the request.
      In the SQL 2008 Server, the "date" type DOES NOT INCLUDE the 00:00:00 part, since it is NOT a datetime, but a date. So where does the 00:00:00 part come from ?
      Last edited by edulid; 13 Aug 2011, 06:44.

      Comment


        #4
        I solved the problem intercepting the DSResponse and modifying it. Thanks anyway!

        Comment


          #5
          I know this post is almost a year old, but Edulid: can you explain more elaborately how you did this?

          Did you transform the date field into a text field of some sort?

          Comment


            #6
            I will take a look when I get home, tonight or tomorrow.

            By the way, is it possible to get an email notification when someone writes on your thread / on a thread you participated in ? I read your question today only by casuality.

            Comment


              #7
              Well I just wrote a DMI method that converts the date to the desired format:
              modifyResponse():

              SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");
              List fields = (List)dsRequest.getExportFields();
              String f = sdf.format(value_j);
              record.put(fields.get(j), f);

              and this method for converting is called on the doFetch() method:

              public DSResponse doFetch(DSRequest dsRequest, HttpServletRequest servletRequest) throws Exception {
              DSResponse response = dsRequest.execute();

              //we are only interested in xls dsRequests
              if (dsRequest.getExportAs() != null && dsRequest.getExportAs().equals("xls")) {
              modifyResponse(dsRequest, response);
              }

              return response;
              }

              So I just convert the Date to a String in the desired format. For that I use a DMI method. I did not convert the date FIELD to a string field, but the date VALUES using the DMI method.

              So the idea is to change the response before it arrives at the client.
              Last edited by edulid; 5 Jul 2012, 00:21.

              Comment


                #8
                Thanks a lot, I will give this a try!

                Comment

                Working...
                X