How To Set Excel Column Format Latebinding

private void WriteToExcel(ref System.Data.DataTable dtExcel)
//Microsoft.Office.Interop.Excel.Application oXL = null;
//Microsoft.Office.Interop.Excel._Workbook oWB;s
//Microsoft.Office.Interop.Excel._Worksheet oSheet;
//SaveFileDialog SFD = new SaveFileDialog();
//SFD.Filter = "Excel 97-2003 Workbook(*.xls)|*.xls|Excel Workbook(*.xlsx)|*.xlsx|Excel Binary Workbook(*.xlsb)|*.xlsb|" +
//"Excel Macro-Enabled Workbook(*.xlsm)|*.xlsm";
//SFD.ShowDialog();
/*Cell Format Text,
Format Excel cells to store values as text
Formating Excel cells to text format will solve the problem of losing leading zeo values when you export data from other data sources to excel.
Excel.Range formatRange;
formatRange = xlWorkSheet.get_Range("a1", "b1");
formatRange.NumberFormat = "@";
xlWorkSheet.Cells[1, 1] = "098";
if (dgvData.RowCount == 0)
MessageBox.Show("GridView is Empty.");
return;
tlsStatus.Text = "Export To Excel Strats.... ";
tlsStatus.ForeColor = System.Drawing.Color.DeepPink;
prbExcelGen.Value = 0;
prbExcelGen.Minimum = 0;
prbExcelGen.Maximum = dgvData.RowCount;
prbExcelGen.Step = 1;
prbExcelGen.Refresh();
object objApp_Late;
object objBook_Late;
object objBooks_Late;
object objSheets_Late;
object objSheet_Late;
object objRange_Late;
object[] Parameters;
string[] headers = new string[dgvData .ColumnCount];
string[] columns = new string[dgvData.ColumnCount];
int i = 0;
int c = 0;
for (c = 0; c <= dgvData.ColumnCount - 1; c++)
headers[c] = dgvData.Rows[0].Cells[c].OwningColumn.Name.ToString();
//Convert Cell Names To A,B,C...Z , 65+C=CHR(C)=>A WHEN C=0
i = c + 65;
columns[c] = Convert.ToString((char)i);
try
// Get the class type and instantiate Excel.
Type objClassType;
objClassType = Type.GetTypeFromProgID("Excel.Application");
objApp_Late = Activator.CreateInstance(objClassType);
//Get the workbooks collection.
objBooks_Late = objApp_Late.GetType().InvokeMember("Workbooks",BindingFlags.GetProperty, null, objApp_Late, null);
//Add a new workbook.
objBook_Late = objBooks_Late.GetType().InvokeMember("Add",BindingFlags.InvokeMethod, null, objBooks_Late, null);
//Get the worksheets collection.
objSheets_Late = objBook_Late.GetType().InvokeMember("Worksheets",BindingFlags.GetProperty, null, objBook_Late, null);
//Get the first worksheet.
Parameters = new Object[1];
Parameters[0] = 1;
objSheet_Late = objSheets_Late.GetType().InvokeMember("Item",
BindingFlags.GetProperty, null, objSheets_Late, Parameters);
//if (true)
// Create the headers in the first row of the sheet
for (c = 0; c <= dgvData.ColumnCount - 1; c++)
//Get a range object that contains cell.
Parameters = new Object[2];
Parameters[0] = columns[c] + "1";
Parameters[1] = Missing.Value;
objRange_Late = objSheet_Late.GetType().InvokeMember("Range",
BindingFlags.GetProperty, null, objSheet_Late, Parameters);
//Write Headers in cell.
Parameters = new Object[1];
Parameters[0] = headers[c];
objRange_Late.GetType().InvokeMember("Value", BindingFlags.SetProperty,
null, objRange_Late, Parameters);
// Now add the data from the grid to the sheet starting in row 2
for (i = 0; i < dgvData.RowCount - 1; i++)
prbExcelGen.PerformStep();
prbExcelGen.Refresh();
for (c = 0; c <= dgvData.ColumnCount - 1; c++)
//Get a range object that contains cell.
Parameters = new Object[2];
Parameters[0] = columns[c] + Convert.ToString(i + 2);
Parameters[1] = Missing.Value;
objRange_Late = objSheet_Late.GetType().InvokeMember("Range",
BindingFlags.GetProperty, null, objSheet_Late, Parameters);
//Write Headers in cell.
Parameters = new Object[1];
Parameters[0] = dgvData.Rows[i].Cells[headers[c]].Value.ToString();
objRange_Late.GetType().InvokeMember("Value", BindingFlags.SetProperty,
null, objRange_Late, Parameters);
//if (i == 0)
// BoldRow(i, c, (EXL._Worksheet)objSheet_Late);
tlsStatus.Text = "Exporting Records...." + i;
//Return control of Excel to the user.
Parameters = new Object[1];
Parameters[0] = true;
tlsStatus.Text = "Exporting Completed.";
objApp_Late.GetType().InvokeMember("Visible", BindingFlags.SetProperty,
null, objApp_Late, Parameters);
objApp_Late.GetType().InvokeMember("UserControl", BindingFlags.SetProperty,
null, objApp_Late, Parameters);
* oWB.SaveAs(fileName, Excel.XlFileFormat.xlOpenXMLWorkbook,
missing, missing, missing, missing,
Excel.XlSaveAsAccessMode.xlNoChange,
missing, missing, missing, missing, missing);
//oWB = (Microsoft.Office.Interop.Excel._Workbook)objBook_Late;
//oWB.SaveAs("file", EXL.XlFileFormat.xlXMLSpreadsheet, Type.Missing, Type.Missing, Type.Missing, Type.Missing, EXL.XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
//oWB.Save();
catch (Exception theException)
String errorMessage;
errorMessage = "Error: ";
errorMessage = String.Concat(errorMessage, theException.Message);
errorMessage = String.Concat(errorMessage, " Line: ");
errorMessage = String.Concat(errorMessage, theException.Source);
MessageBox.Show(errorMessage);
finally
using the above code i am writing to excel sheet can some one help me to tell how can i set a column type as text 

Thanks Forum,
i got the answer here
https://social.msdn.microsoft.com/Forums/windows/en-US/36340ada-e13b-41cb-a31d-fb76121aa0d2/c-exporting-text-file-to-excel-and-column-formatting-problem?forum=csharpgeneral

Similar Messages

  • How do I maintain column formatting when converting from PDF to Excel?

    How do I maintain column formatting when converting from PDF to Excel? All info is no longer on the lines or in the columns they started out being in? Any help would be appreciated.

    Sara,
    Perhaps I am expecting too much from Adobe ExportPDF. The reason I subscribed to this service, for which I pay a yearly fee, was that I need a way to  convert scanned and digital documents to Word &/or Excel. I read the link you included but to be candid the more I tried to understand what was written the more confused I got. The process should not be this difficult. Currently I am using a NEAT scanner to create PDF documents of whatever I scan. After I changed the OCR setting on Adobe ExportPDF the output was much better but not to the point it was usable as it was. Information that appears to be lines and columns are sometimes not recognizing two columns and just putting them together in one. Obviously not usable. The other thing it does is bunch numbers that appear in a column that are just a bunch of numbers that I have no way of fixing. 
    Please let me speak to someone who can help me. Right now I not getting anything of value in my paid subscription.

  • How to set the column order of a sealed column in a custom Content Type for the new item form NewDocSet.aspx?

    Dear SharePoint Developers,
    Please help.
    I need to know How to set the column order of a sealed column in a custom Content Type for the new item form NewDocSet.aspx?
    I think this is a "sealed column", whatever that is, which is  shown in SPD 2013 as a column of content type "document, folder, MyCustomContentType".
    I know when I set the column order in my custom Content Type settings page, it is correct.
    But, when I load the NewDocSet.aspx page, the column order that I set in the settings page is NOT used for this "sealed column" which is bad.
    Can you help?
    Please advise.
    Thanks.
    Mark Kamoski
    -- Mark Kamoski

    Hi,
    According to your post, my understanding is that you want to set the column order of a sealed column in a custom Content Type for the new item form NewDocSet.aspx.
    Per my knowledge, if you have Content Type management enabled for the list or library (if you see a list of content type with the option to add more), the display order of columns is set for each content type.
    Drill down into one of them and you'll see the option under the list of columns for that content type.
    To apply the column order in the NewDocSet.aspx page, you need to:
    Select Site Settings, under Site Collection Administration, click Content type publishing. In the Refresh All Published
    Content Types section, choose Refresh all published content types on next
    update.
    Run two timer jobs(Content Type Hub, Content Type Subscriber) in central admin(Central Administration--> Monitoring--> Review timer jobs).
    More information:
    http://sharepoint.stackexchange.com/questions/95028/content-types-not-refreshing-on-sp-online
    Best Regards,
    Linda Li
    Linda Li
    TechNet Community Support

  • How to set displayed column width for a search help

    I have created an elementary search help for a custom field with a value table behind it.
    The search help functions correctly, but when displayed the column widths are all 10 characters. The user has to adjust the column to view the descriptive text.
    Can anyone tell me how to set default column widths for the help?

    Please  open you Elementary search  help  and see the Column  width   behind the Fields of your ...there  increase the width of the fields
    "Activate it  and refresh
    reward  points if it is usefull .....
    Girish

  • How to set unequal columns using master pages in InDesign CS3?

    How to set unequal columns using master pages in InDesign CS3?

    I don't have CS3 anymore but I don't think this has substantially changed in the last few versions of InDesign.
    Choose View > Grids & Guides > uncheck Lock Column Guides. Then drag the column guides to the position you want.

  • How to set the column table so it can not be moved !

    how to set the column table so it can not be moved !

    m_table.getTableHeader().setReorderingAllowed(false);
    m_table.getTableHeader().setResizingAllowed(false);

  • How to add "Done" button on Number pad? And how to set 00.00 format for UITextField?

    1.) I am new to iPhone development. I have a small application & for that I need to add number pad but there is no "Done" button. I know we can get rid of that keyboard by clinking UIView but I want a separate button for this.
    2.) My second question is how to set 00.00 format for UITextField as there is no decimal point available on number pad?

    As to #1, you should study the iOS HIG - doing what you have in mind might be a good way to risk rejection and not have your app make it into the store.
    #2:
    On devices running iOS v4.1 and greater  you can use the following:
    myTextField.keyboardType = UIKeyboardTypeDecimalPad;
    It is tricky (and perhaps not worth the trouble) if you are trying to support older iOS versions.  Here is a link to the most popular solution.

  • How to set first column as date (dd/mm/yyyy) in the specific format in excel

    hi need help wat i did need help is tht i need wen ever i send view a excel data  the first column set to date  but some times wen i view in different type of pc the date format change to mm/dd/yyyy. is  thr any way i can set the format?

    If you just need to reformat a correct date to show up as dd/mm/yyyy, just use the "Format Cells" command and set a custom format string to exactly that. If, on the other hand, you are finding that Excel just doesn't get that the first value is a DAY, not a month, such as trying to graph a temperature data logger that records data in dd/mm/yyyy:
    Reformat the strings as dd/mm/yyyy, using the first method. This will make them LOOK correct, even though the actual date VALUES are still day-month inverted. Now save the table as a .CSV file. This will save the dates as plain text in the correct order, which you can then re-import and have Excel now read the correct date value.
    Ryan R.
    R&D

  • OLE2 how to set a column width of an excel file i'm creating?

    how can i set the column width in an excel file i'm creating with ole?
    or even, haw can i set the auto-fix properties?

    Hallo !
    SORRY MY ENGLISH is very BAD.
    I tried to set page header and  footer in Excel sheet with abap ole
    DATA : BEGIN OF enter,
             x(1) TYPE x VALUE '0D',
            END OF enter.
    DATA : format(255) TYPE c.
    FORM set_page_sheet.
      CALL METHOD OF excel 'ActiveSheet' = sheet.
      CALL METHOD OF sheet 'PageSetup' = pagesetup.
      SET PROPERTY OF pagesetup 'Orientation' = xllandscape.
      SET PROPERTY OF pagesetup 'PrintTitleRows' = '$9:$12'.
      CLEAR format.
    ERROR
      CONCATENATE 'PAGESHEET' enter-x 'PAGE &P/&N' INTO format.
    ERROR
      SET PROPERTY OF pagesetup 'RightHeader' = format.
      CLEAR format.
      CONCATENATE ' Text 1 ' enter-x 'Text 2'
    enter-x 'Text 3 ' INTO format.
      SET PROPERTY OF pagesetup 'RightFooter' = format.
      FREE OBJECT pagesetup.
    ENDFORM.                    " set_page_sheet
    Activate report -
    ERROR - The enter-x must by data type c or another then data type x
    Thanks for answer.

  • How to set the column size in OATable

    Hi All,
    I'm using Oracle EBS 11.5.10
    I have a OATable with two columns (messagestyledText), say Col01 and Col02.
    Is there a way that I can set the width of Col01 and Col02 ? As in 30% of OATable for Col01 and 70% for col02?
    Thanks for any suggestion/help,
    Elmer

    Hi All,
    Got the answer. How I wish this can be define declaratively.
    Code below for the soln.
    OATableBean table01 = (OATableBean)webBean.findChildRecursive("table01RN");
    table01.queryData(pageContext, true);
    table01.prepareForRendering(pageContext);
    DataObjectList aColFormat01 = table01.getColumnFormats() ;
    oracle.cabo.ui.data.DictionaryData ColFormat01 =(oracle.cabo.ui.data.DictionaryData)aColFormat01.getItem(pageContext.findChildIndex(table01, "ColLabel"));
    //Column Width
    ColFormat01.put(WIDTH_KEY, "30%");
    //Column Format - Right-aligned varchar
    ColFormat01.put(COLUMN_DATA_FORMAT_KEY,NUMBER_FORMAT);cheers,
    Elmer
    Edited by: Elmer on Mar 8, 2010 2:46 AM

  • How to make excel columns width autofit  ?

    Hello  Experts ,
    I download data from an internal table  to create an excel attached file and send it to customers by mail. The excel sheet looks untidy .
    the columns width of excel are not autofit .
    It's default 8.43 character .  Costomers can not use equally excel tools. eg.  format->column->autofit selection in excel.
    I was wondering how to make all excel columns' width autofit by means of ABAP . Is there any way to reach this property of excel via SAP  when I send excel attached files from an internal table .
    suggestions will be rewarded .
    Regards ,

    Hi Rajkumar or all,
    If any one able to display the records more than 65k line in Bex report v7.0..
    Pls reply with detail expalination.. Thanks in advance.. will give the reward points..
    Waiting urgently for your response..

  • How to set default export format in Crystal Reports Viewer

    When Viewing Crystal Reports, the top left button can choose export file format, how to set it default to Excel?
    If we can only go with hidden the button, and create a new button, any one can kindly provide how to?
    The BOE version is XI R2 SP2.
    Thanks in advance!
    Jennie

    hi all , i have same problem like i want only 1 report to be generated like for ex:only PDF should be generated n all others has to be disabled. my jsp is as follows:
    <%@page import="com.abc.def.crystalReports.JRCHelper,
    com.crystaldecisions.reports.reportengineinterface.*,
    com.crystaldecisions.report.web.viewer.CrystalReportPartsViewer,
    com.crystaldecisions.report.web.viewer.CrystalReportViewer,
    com.crystaldecisions.reports.sdk.ReportClientDocument,
    com.crystaldecisions.sdk.occa.report.application.OpenReportOptions,
    com.crystaldecisions.sdk.occa.report.lib.ReportSDKExceptionBase,
    com.crystaldecisions.sdk.occa.report.reportsource.IReportSource,
    com.crystaldecisions.report.web.viewer.*,
    com.crystaldecisions.sdk.occa.report.exportoptions.*,
    java.sql.Connection,
    java.sql.DriverManager,
    java.sql.ResultSet,
    java.sql.SQLException,
    java.sql.Statement,
    java.util.ResourceBundle"%><%
         // This sample code calls methods from the JRCHelperSample class, which
         // contains examples of how to use the BusinessObjects APIs. You are free to
         // modify and distribute the source code contained in the JRCHelperSample class.
         try {
              ResourceBundle messageBundle = ResourceBundle.getBundle("resources.ApplicationResources");
              String reportName = messageBundle.getString("report.path");
              ReportClientDocument clientDoc = (ReportClientDocument) session.getAttribute(reportName);
              if (clientDoc == null) {
                   // Report can be opened from the relative location specified in the CRConfig.xml, or the report location
                   // tag can be removed to open the reports as Java resources or using an absolute path
                   // (absolute path not recommended for Web applications).
                   clientDoc = new ReportClientDocument();
                   // Open report
                   clientDoc.open(reportName, OpenReportOptions._openAsReadOnly);
                   // ****** BEGIN CHANGE DATASOURCE SNIPPET **************** 
                        String connectString = "jdbc:oracle:thin:@****:db;
                        String driverName = "oracle.jdbc.driver.OracleDriver";
                        String JNDIName = "";
                        String userName = "root";               // TODO: Fill in database user
                        String password = "root";          // TODO: Fill in password
                        // Switch all tables on the main report and sub reports
                        JRCHelper.changeDataSource(clientDoc, userName, password, connectString, driverName, JNDIName);
                   // ****** END CHANGE DATASOURCE SNIPPET ****************      
                   // Store the report document in session
                   session.setAttribute(reportName, clientDoc);
                   // ****** BEGIN CONNECT CRYSTALREPORTPAGEVIEWER SNIPPET **************** 
                        // Create the CrystalReportViewer object
                        CrystalReportViewer crystalReportPageViewer = new CrystalReportViewer();
                        ReportExportControl exporter = new ReportExportControl();
                        //     set the reportsource property of the viewer
                        JPEReportSourceFactory rptSrcFactory = new JPEReportSourceFactory();
                        IReportSource reportSource = (IReportSource)rptSrcFactory.createReportSource(reportName,request.getLocale());
                        Boolean b1 = new Boolean(messageBundle.getString("Toggle.Group.TreeButton"));
                        Boolean b2 = new Boolean(messageBundle.getString("Has.ExportButton"));
                        Boolean b3 = new Boolean(messageBundle.getString("Has.SearchButton"));
                        Boolean b4 = new Boolean(messageBundle.getString("Display.GroupTree"));
                        Boolean b5 = new Boolean(messageBundle.getString("Has.Logo"));
                        Boolean b6 = new Boolean(messageBundle.getString("Display.Toolbar"));
                        crystalReportPageViewer.setHasToggleGroupTreeButton(true);
                        crystalReportPageViewer.setHasExportButton(true);
                        crystalReportPageViewer.setHasSearchButton(false);
                        crystalReportPageViewer.setDisplayGroupTree(false);
                        crystalReportPageViewer.setHasLogo(false);
                        crystalReportPageViewer.setOwnPage(true);
                        crystalReportPageViewer.setOwnForm(true);
                        crystalReportPageViewer.setReportSource(reportSource);
                        crystalReportPageViewer.processHttpRequest(request, response, application, null);
                        IReportSource reportSource = (IReportSource)rptSrcFactory.createReportSource(reportName,request.getLocale());
                        //CharacterSeparatedValuesExportFormatOptions csvOptions = new CharacterSeparatedValuesExportFormatOptions();
                        ExportOptions exportOptions = new ExportOptions();
                        //exportOptions.setExportFormatType(ReportExportFormat.characterSeparatedValues);
                        //exportOptions.setExportFormatType(ReportExportFormat.PDF);     
                        exportOptions.setExportFormatType(ReportExportFormat.characterSeparatedValues);
                        exporter.setReportSource(reportSource);
                        exporter.setExportOptions(exportOptions);
                   //exporter.setExportAsAttachment(true);
                        exporter.processHttpRequest(request, response, application, null);
                   // ****** END CONNECT CRYSTALREPORTPAGEVIEWER SNIPPET ****************          
         } catch (ReportSDKExceptionBase e) {
             out.println(e);
    %>
    if i want to add custom button where to add

  • How to set default export format in CrystalReports Viewer

    When Viewing Crystal Reports in InfoView, the top left button can choose export file format, how to set it default to Excel?

    Hi Jennie Xiang,
    You can set the default export format in Crystal designer before publishing in infoview.
    Open the report in Crystal designer and go to file>export>export options--> select the export option to xls and check the options that you want and click on OK.
    Now try exporting the report by clicking on export button then you can see the first option as xls with all format options that you have selected before by default.
    By saving this report at server (infoview) you can get the same options while exporting from viewer.
    Regards,
    Ragahvendra

  • How to set a column size in sqldeveloper?

    Like in subject.. I want to set standard output in sqldeveloper, but this command doesn't work:
    column object_name Heading 'name' format a40
    Someone know where it should be set?
    I think about "Script output" of course!! Not any graphical one ;)
    Message was edited by:
    user584507

    The statement column is not supported in SQL Developer.
    See Help > SQL Developer Concepts and Usage > Using the SQL Worksheet > SQL*Plus Statements Supported and Not Supported in SQL Worksheet.
    But you can use substr in the select statement to set the column width.
    For example:
    select substr(object_name,1,40) "Object", object_name
    from user_objects
    Run the statement as a script and see the difference between both columns.

  • How to set JTable column's color?

    How can I set JTable Columns' color? I only found this class DefaultTableCellRenderer
    which can set cell's color.

    rmalina wrote:
    You are going to need to derive a renderer class for your Column from DefaultTableCellRenderer and override the following function with something like this:
    @Override
         public Component getTableCellRendererComponent(JTable jTable, Object oValue, boolean isSelected, boolean hasFocus, int nRow, int nColumn) {
    super.setForeground(Color.GREEN);
    super.setBackground(Color.GREEN);
    }That would set your column to green.
    Edited by: rmalina on Jul 28, 2008 8:47 AMHow can I know I only change the columns' color instead of other cells?

Maybe you are looking for