Change the Excel column format from number to Text in JavaHow to round a number to n decimal places in JavaHow do I call one constructor from another in Java?How do I create a Java string from the contents of a file?How to get an enum value from a string value in Java?How to get the current time in YYYY-MM-DD HH:MI:Sec.Millisecond format in Java?How to append text to an existing file in JavaReading a plain text file in JavaChange date format in a Java stringRemoving whitespace from strings in JavaHow to read a large text file line by line using Java?
Will using a resistor in series with a LED to control its voltage increase the total energy expenditure?
How can I shoot a bow using strength instead of dexterity?
"Mouth-breathing" as slang for stupidity
What is the most difficult concept to grasp in Calculus 1?
How to gracefully leave a company you helped start?
Are there really no countries that protect Freedom of Speech as the United States does?
graphs in latex
Prestidigitation to replace bathing and washing clothes worn?
What is the farthest a camera can see?
Doesn't the speed of light limit imply the same electron can be annihilated twice?
What should I do if actually I found a serious flaw in someone's PhD thesis and an article derived from that PhD thesis?
Bringing Power Supplies on Plane?
How far did Gandalf and the Balrog drop from the bridge in Moria?
Cycle of actions and voice signals on a multipitch climb
K-Type Thermocouple, Instrumentation Op-Amp and Arduino
Does an Irish VISA WARNING count as "refused entry at the border of any country other than the UK?"
Should I leave building the database for the end?
Why not demand President's/candidate's financial records instead of tax returns?
Help, I cannot decide when to start the story
Why aren’t there water shutoff valves for each room?
Are there examples in Tanach of 3 or more parties having an ongoing conversation?
Do beef farmed pastures net remove carbon emissions?
Why is there a large performance impact when looping over an array with 240 or more elements?
Shifting tenses in the middle of narration
Change the Excel column format from number to Text in Java
How to round a number to n decimal places in JavaHow do I call one constructor from another in Java?How do I create a Java string from the contents of a file?How to get an enum value from a string value in Java?How to get the current time in YYYY-MM-DD HH:MI:Sec.Millisecond format in Java?How to append text to an existing file in JavaReading a plain text file in JavaChange date format in a Java stringRemoving whitespace from strings in JavaHow to read a large text file line by line using Java?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I'm trying to create an Excel template with all the columns / cells as text.
The Excel sheet has 5 columns
Here is my code:
@RequestMapping(value = "/app/downloadTemplateForAssociateBankingDetails", method = RequestMethod.GET)
public void downloadTemplateForAssociateBankingDetails(HttpServletRequest request,HttpServletResponse response) throws Exception
@SuppressWarnings("resource")
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet("AssociateBankingTemplate");
String[] tableColumns = Constants.DATA_MIGRATION_ASSOCIATE_BANKING_EXCEL_HEADERS;
DataFormat fmt = workbook.createDataFormat();
CellStyle cellStyle = workbook.createCellStyle();
Row row = sheet.createRow(0);
int cellnum = 0;
for (String key : tableColumns)
Cell cell = row.createCell(cellnum++);
cellStyle.setDataFormat(
fmt.getFormat("@"));
cell.setCellStyle(cellStyle);
cell.setCellValue((String)key);
try
File file = new File("Associate_Banking_Template.xls");
FileOutputStream out = new FileOutputStream(file);
workbook.write(out);
out.close();
out.flush();
String mimeType = URLConnection.guessContentTypeFromName(file.getName());
if (mimeType == null)
mimeType = "application/octet-stream";
response.setContentType(mimeType);
StringBuilder fileNameSB = new StringBuilder();
response.setHeader("Content-Disposition", fileNameSB.append("attachment; filename="").append(file.getName()).append(""").toString());
response.setContentLength((int) file.length());
InputStream inputStream = new BufferedInputStream(new FileInputStream(file));
FileCopyUtils.copy(inputStream, response.getOutputStream());
inputStream.close();
response.getOutputStream().close();
response.getOutputStream().flush();
catch (Exception e)
e.printStackTrace();
java spring-mvc apache-poi
add a comment |
I'm trying to create an Excel template with all the columns / cells as text.
The Excel sheet has 5 columns
Here is my code:
@RequestMapping(value = "/app/downloadTemplateForAssociateBankingDetails", method = RequestMethod.GET)
public void downloadTemplateForAssociateBankingDetails(HttpServletRequest request,HttpServletResponse response) throws Exception
@SuppressWarnings("resource")
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet("AssociateBankingTemplate");
String[] tableColumns = Constants.DATA_MIGRATION_ASSOCIATE_BANKING_EXCEL_HEADERS;
DataFormat fmt = workbook.createDataFormat();
CellStyle cellStyle = workbook.createCellStyle();
Row row = sheet.createRow(0);
int cellnum = 0;
for (String key : tableColumns)
Cell cell = row.createCell(cellnum++);
cellStyle.setDataFormat(
fmt.getFormat("@"));
cell.setCellStyle(cellStyle);
cell.setCellValue((String)key);
try
File file = new File("Associate_Banking_Template.xls");
FileOutputStream out = new FileOutputStream(file);
workbook.write(out);
out.close();
out.flush();
String mimeType = URLConnection.guessContentTypeFromName(file.getName());
if (mimeType == null)
mimeType = "application/octet-stream";
response.setContentType(mimeType);
StringBuilder fileNameSB = new StringBuilder();
response.setHeader("Content-Disposition", fileNameSB.append("attachment; filename="").append(file.getName()).append(""").toString());
response.setContentLength((int) file.length());
InputStream inputStream = new BufferedInputStream(new FileInputStream(file));
FileCopyUtils.copy(inputStream, response.getOutputStream());
inputStream.close();
response.getOutputStream().close();
response.getOutputStream().flush();
catch (Exception e)
e.printStackTrace();
java spring-mvc apache-poi
Everytime getting cell format as Number not text
– Rajat Rana
Mar 27 at 11:25
add a comment |
I'm trying to create an Excel template with all the columns / cells as text.
The Excel sheet has 5 columns
Here is my code:
@RequestMapping(value = "/app/downloadTemplateForAssociateBankingDetails", method = RequestMethod.GET)
public void downloadTemplateForAssociateBankingDetails(HttpServletRequest request,HttpServletResponse response) throws Exception
@SuppressWarnings("resource")
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet("AssociateBankingTemplate");
String[] tableColumns = Constants.DATA_MIGRATION_ASSOCIATE_BANKING_EXCEL_HEADERS;
DataFormat fmt = workbook.createDataFormat();
CellStyle cellStyle = workbook.createCellStyle();
Row row = sheet.createRow(0);
int cellnum = 0;
for (String key : tableColumns)
Cell cell = row.createCell(cellnum++);
cellStyle.setDataFormat(
fmt.getFormat("@"));
cell.setCellStyle(cellStyle);
cell.setCellValue((String)key);
try
File file = new File("Associate_Banking_Template.xls");
FileOutputStream out = new FileOutputStream(file);
workbook.write(out);
out.close();
out.flush();
String mimeType = URLConnection.guessContentTypeFromName(file.getName());
if (mimeType == null)
mimeType = "application/octet-stream";
response.setContentType(mimeType);
StringBuilder fileNameSB = new StringBuilder();
response.setHeader("Content-Disposition", fileNameSB.append("attachment; filename="").append(file.getName()).append(""").toString());
response.setContentLength((int) file.length());
InputStream inputStream = new BufferedInputStream(new FileInputStream(file));
FileCopyUtils.copy(inputStream, response.getOutputStream());
inputStream.close();
response.getOutputStream().close();
response.getOutputStream().flush();
catch (Exception e)
e.printStackTrace();
java spring-mvc apache-poi
I'm trying to create an Excel template with all the columns / cells as text.
The Excel sheet has 5 columns
Here is my code:
@RequestMapping(value = "/app/downloadTemplateForAssociateBankingDetails", method = RequestMethod.GET)
public void downloadTemplateForAssociateBankingDetails(HttpServletRequest request,HttpServletResponse response) throws Exception
@SuppressWarnings("resource")
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet("AssociateBankingTemplate");
String[] tableColumns = Constants.DATA_MIGRATION_ASSOCIATE_BANKING_EXCEL_HEADERS;
DataFormat fmt = workbook.createDataFormat();
CellStyle cellStyle = workbook.createCellStyle();
Row row = sheet.createRow(0);
int cellnum = 0;
for (String key : tableColumns)
Cell cell = row.createCell(cellnum++);
cellStyle.setDataFormat(
fmt.getFormat("@"));
cell.setCellStyle(cellStyle);
cell.setCellValue((String)key);
try
File file = new File("Associate_Banking_Template.xls");
FileOutputStream out = new FileOutputStream(file);
workbook.write(out);
out.close();
out.flush();
String mimeType = URLConnection.guessContentTypeFromName(file.getName());
if (mimeType == null)
mimeType = "application/octet-stream";
response.setContentType(mimeType);
StringBuilder fileNameSB = new StringBuilder();
response.setHeader("Content-Disposition", fileNameSB.append("attachment; filename="").append(file.getName()).append(""").toString());
response.setContentLength((int) file.length());
InputStream inputStream = new BufferedInputStream(new FileInputStream(file));
FileCopyUtils.copy(inputStream, response.getOutputStream());
inputStream.close();
response.getOutputStream().close();
response.getOutputStream().flush();
catch (Exception e)
e.printStackTrace();
java spring-mvc apache-poi
java spring-mvc apache-poi
edited Mar 27 at 12:00
Richard Neish
5,5263 gold badges28 silver badges59 bronze badges
5,5263 gold badges28 silver badges59 bronze badges
asked Mar 27 at 11:22
Rajat RanaRajat Rana
31 bronze badge
31 bronze badge
Everytime getting cell format as Number not text
– Rajat Rana
Mar 27 at 11:25
add a comment |
Everytime getting cell format as Number not text
– Rajat Rana
Mar 27 at 11:25
Everytime getting cell format as Number not text
– Rajat Rana
Mar 27 at 11:25
Everytime getting cell format as Number not text
– Rajat Rana
Mar 27 at 11:25
add a comment |
2 Answers
2
active
oldest
votes
Who is telling you that the cell isn't in text format? MS Excel? LibreOffice Calc?
The following code works for me and should give you a cell in text format.
public class TextFormat
public static void main(String[] args) throws Exception
Workbook workbook = new HSSFWorkbook();
Sheet sheet = workbook.createSheet("sheet");
Row row = sheet.createRow(0);
Cell cell = row.createCell(0);
cell.setCellValue("Text");
CellStyle cellStyle = workbook.createCellStyle();
DataFormat fmt = workbook.createDataFormat();
cellStyle.setDataFormat(fmt.getFormat("@"));
cell.setCellStyle(cellStyle);
OutputStream fileOut = new FileOutputStream("workbook.xls");
workbook.write(fileOut);
workbook.close();
LibreOffice Calc
– Rajat Rana
Mar 29 at 6:12
When you try my code, openworkbook.xls
, right click on the first cell and select “Format Cells...” then you should see the format code is set to @.
– Martin
Mar 29 at 6:43
add a comment |
Something like:
Worksheets("Sheet1").Range("A17").NumberFormat = "@"
I am not sure but I think that "@" means Text format.
That is only for one cell, if you want all cells I think it could be something like this:
Worksheets("Sheet1").Range("B:B").NumberFormat="@"
in case you want only column B
`Worksheets("Sheet1").Range("A:E").NumberFormat="@"`
if you want all your data is read like a text.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55376007%2fchange-the-excel-column-format-from-number-to-text-in-java%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Who is telling you that the cell isn't in text format? MS Excel? LibreOffice Calc?
The following code works for me and should give you a cell in text format.
public class TextFormat
public static void main(String[] args) throws Exception
Workbook workbook = new HSSFWorkbook();
Sheet sheet = workbook.createSheet("sheet");
Row row = sheet.createRow(0);
Cell cell = row.createCell(0);
cell.setCellValue("Text");
CellStyle cellStyle = workbook.createCellStyle();
DataFormat fmt = workbook.createDataFormat();
cellStyle.setDataFormat(fmt.getFormat("@"));
cell.setCellStyle(cellStyle);
OutputStream fileOut = new FileOutputStream("workbook.xls");
workbook.write(fileOut);
workbook.close();
LibreOffice Calc
– Rajat Rana
Mar 29 at 6:12
When you try my code, openworkbook.xls
, right click on the first cell and select “Format Cells...” then you should see the format code is set to @.
– Martin
Mar 29 at 6:43
add a comment |
Who is telling you that the cell isn't in text format? MS Excel? LibreOffice Calc?
The following code works for me and should give you a cell in text format.
public class TextFormat
public static void main(String[] args) throws Exception
Workbook workbook = new HSSFWorkbook();
Sheet sheet = workbook.createSheet("sheet");
Row row = sheet.createRow(0);
Cell cell = row.createCell(0);
cell.setCellValue("Text");
CellStyle cellStyle = workbook.createCellStyle();
DataFormat fmt = workbook.createDataFormat();
cellStyle.setDataFormat(fmt.getFormat("@"));
cell.setCellStyle(cellStyle);
OutputStream fileOut = new FileOutputStream("workbook.xls");
workbook.write(fileOut);
workbook.close();
LibreOffice Calc
– Rajat Rana
Mar 29 at 6:12
When you try my code, openworkbook.xls
, right click on the first cell and select “Format Cells...” then you should see the format code is set to @.
– Martin
Mar 29 at 6:43
add a comment |
Who is telling you that the cell isn't in text format? MS Excel? LibreOffice Calc?
The following code works for me and should give you a cell in text format.
public class TextFormat
public static void main(String[] args) throws Exception
Workbook workbook = new HSSFWorkbook();
Sheet sheet = workbook.createSheet("sheet");
Row row = sheet.createRow(0);
Cell cell = row.createCell(0);
cell.setCellValue("Text");
CellStyle cellStyle = workbook.createCellStyle();
DataFormat fmt = workbook.createDataFormat();
cellStyle.setDataFormat(fmt.getFormat("@"));
cell.setCellStyle(cellStyle);
OutputStream fileOut = new FileOutputStream("workbook.xls");
workbook.write(fileOut);
workbook.close();
Who is telling you that the cell isn't in text format? MS Excel? LibreOffice Calc?
The following code works for me and should give you a cell in text format.
public class TextFormat
public static void main(String[] args) throws Exception
Workbook workbook = new HSSFWorkbook();
Sheet sheet = workbook.createSheet("sheet");
Row row = sheet.createRow(0);
Cell cell = row.createCell(0);
cell.setCellValue("Text");
CellStyle cellStyle = workbook.createCellStyle();
DataFormat fmt = workbook.createDataFormat();
cellStyle.setDataFormat(fmt.getFormat("@"));
cell.setCellStyle(cellStyle);
OutputStream fileOut = new FileOutputStream("workbook.xls");
workbook.write(fileOut);
workbook.close();
edited Mar 27 at 16:18
answered Mar 27 at 16:00
MartinMartin
1039 bronze badges
1039 bronze badges
LibreOffice Calc
– Rajat Rana
Mar 29 at 6:12
When you try my code, openworkbook.xls
, right click on the first cell and select “Format Cells...” then you should see the format code is set to @.
– Martin
Mar 29 at 6:43
add a comment |
LibreOffice Calc
– Rajat Rana
Mar 29 at 6:12
When you try my code, openworkbook.xls
, right click on the first cell and select “Format Cells...” then you should see the format code is set to @.
– Martin
Mar 29 at 6:43
LibreOffice Calc
– Rajat Rana
Mar 29 at 6:12
LibreOffice Calc
– Rajat Rana
Mar 29 at 6:12
When you try my code, open
workbook.xls
, right click on the first cell and select “Format Cells...” then you should see the format code is set to @.– Martin
Mar 29 at 6:43
When you try my code, open
workbook.xls
, right click on the first cell and select “Format Cells...” then you should see the format code is set to @.– Martin
Mar 29 at 6:43
add a comment |
Something like:
Worksheets("Sheet1").Range("A17").NumberFormat = "@"
I am not sure but I think that "@" means Text format.
That is only for one cell, if you want all cells I think it could be something like this:
Worksheets("Sheet1").Range("B:B").NumberFormat="@"
in case you want only column B
`Worksheets("Sheet1").Range("A:E").NumberFormat="@"`
if you want all your data is read like a text.
add a comment |
Something like:
Worksheets("Sheet1").Range("A17").NumberFormat = "@"
I am not sure but I think that "@" means Text format.
That is only for one cell, if you want all cells I think it could be something like this:
Worksheets("Sheet1").Range("B:B").NumberFormat="@"
in case you want only column B
`Worksheets("Sheet1").Range("A:E").NumberFormat="@"`
if you want all your data is read like a text.
add a comment |
Something like:
Worksheets("Sheet1").Range("A17").NumberFormat = "@"
I am not sure but I think that "@" means Text format.
That is only for one cell, if you want all cells I think it could be something like this:
Worksheets("Sheet1").Range("B:B").NumberFormat="@"
in case you want only column B
`Worksheets("Sheet1").Range("A:E").NumberFormat="@"`
if you want all your data is read like a text.
Something like:
Worksheets("Sheet1").Range("A17").NumberFormat = "@"
I am not sure but I think that "@" means Text format.
That is only for one cell, if you want all cells I think it could be something like this:
Worksheets("Sheet1").Range("B:B").NumberFormat="@"
in case you want only column B
`Worksheets("Sheet1").Range("A:E").NumberFormat="@"`
if you want all your data is read like a text.
answered Mar 27 at 11:53
AdriánAdrián
14 bronze badges
14 bronze badges
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55376007%2fchange-the-excel-column-format-from-number-to-text-in-java%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Everytime getting cell format as Number not text
– Rajat Rana
Mar 27 at 11:25