Bill Melendez

Greenhorn
+ Follow
since Apr 08, 2019
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
2
Received in last 30 days
2
Total given
3
Given in last 30 days
1
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Bill Melendez

Ron:

Thank you so much for your persistence and support on this. I added the two lines you sent me and the reason the program didn't send the other 2 attachments was that I had the wrong file ending. It should have been "csv" and not "xlsx". Honestly, I was embarrassed since I then remember that the two spreadsheet files were actually exported database field entries --so the extension should have been "csv". The program now sends all three files without any issues. Thank you.

Is there some checkmark or uptick for this to show my approval of your support?
6 days ago
Ron:

I changed the JavaMail to 1.6.2 but get the same error codes.
1 week ago
With the messageBodyPart3 and messageBodyPart4 included in the code I get an error message that states it can't find the next file (Plumb1-13052021.xlsx). However, all three files are in the same directory and it has no problem finding the first attachment (Plumb-13052021.docx). So it runs okay with the 3rd and 4th attachments "commented out." The error states it can't find the next attachment (Plumb1-13052021.xlsx) even though it has no problem locating the first one.

I'm using Java.mail-1.6.0 and activation-1.1. Here's error I'm getting:

1 week ago
Tried to post the other day --seems it didn't take. So I'm trying again. The attached program still will not let me send more than one attachment. I get a null exception.

1 week ago
Thank you! Here's the code. I am using the one posted last, though either one would work with just one attachment --but not two or three.
1 week ago
Paul, Ron:

Ron -- I see what you are referring to -the msg.setContent is within the loop so it gets replaced each time. That seems to be the problem even with the version you posted. Here's why: I can comment out the 2nd and 3rd files and the program will send the 1st file easily in both Paul's and yours. In both versions (Paul & Ron) the program can't find the following files even though all three files are in the same directory. However, I did set print so I can see that the array is working fine and the files are being accessed sequentially. However, only the last file itinerary is actually used.  Since I have 4 loops, the last file added is the first one.

I tried moving the setContent outside the "for loop" but then I get an error stating that multipart can't be found.  I do agree with your assessment as to the setContent getting files replaced each time the loop calls a new file. Just don't know how to resolve that. The problem is consistent with each version sample I use. All other portions work fine --multipart just will not keep all three files -- merely replaces each file as the new one is called.

Any help would be greatly appreciated.
1 week ago
Paul:

Thank you so much for your willingness to help me with this. I redid the multipart section to reduce some of the clutter and am still getting just one attachment being sent. I read your tutorial and it helped me reduce all the excess code lines. However, I still can't seem to attach the 2nd and 3rd file attachments. It attaches the first file with no problem and sends the email to the recipient. Below are the multipart changes I made.  I use System print to verify that the file selection and the attachment part were not empty. Both seem to be working okay. I'm just missing something in my code to tell the multipart that it needs to recognize each file independently and keep them as attachments.


2 weeks ago
The below code sends 1 attachment to a recipient. However, I need to send 3 files to the recipient. This is my first attempt at using JavaMail and the am finding difficulty resolving the "multipart" section to accept 3 files. The issue is that while each file is selected and each multipart is there, the last portion of the multipart (multipart3 and multipart4) is not added to the message. If  I comment out the last two (multipart3 and multipart4) lines of the msg.setContent, then the message goes through with the first attachment. Really could use some help in this.

2 weeks ago
Paul:  I did! I was able to create a font method for it. Again thanks.
5 months ago
Paul:

Thank you so much. You solve the problem and I do appreciate your help. Hope your Holiday Season is full of Christmas joy.
5 months ago
As you probably guessed, I'm not an expert on JAVA, and not sure how I would use a method that handles the repeated codes. The only changes are the variables and the row/cell locations. Any suggestion would be greatly appreciated.
5 months ago
Here's the code that doesn't work. It is the same as the previous code except for the variable and the row/cell locations:

                //Space Two entries line 18 of Spreadsheet (line 17 of POI)
               If  (PRO6X.length()>0){
                XSSFRow row20 = sheet.getRow(17);
              cell = row20.getCell(4);
                   style2= cell.getCellStyle();
                style2.setFont(font3);
                cell.setCellStyle(style2);
                cell.setCellValue(PRO6X);
           
                XSSFRow row21 = sheet.getRow(17);
                cell = row21.getCell(6);
                style2= cell.getCellStyle();
                style2.setFont(font3);
                cell.setCellStyle(style2);
                cell.setCellValue(PRO6XQ);
               
               }
         
           
            //Counters entries line 23 of the spreadsheet (line 22 of POI)
           
          If  (PRO11X.length()>0){
               XSSFRow row30 = sheet.getRow(22);
               cell = row30.getCell(4);
               style2= cell.getCellStyle();
               style2.setFont(font3);
               cell.setCellStyle(style2);
               cell.setCellValue(PRO11X);
           
               XSSFRow row31 = sheet.getRow(22);
               cell = row31.getCell(6);
               style2= cell.getCellStyle();
               style2.setFont(font3);
               cell.setCellStyle(style2);
               cell.setCellValue(PRO11XQ);
               
           }
           
            //Transmitter entries line 24 of spreadsheet (line 23 of POI)
           
             If  (PRO12X.length()>0){
               XSSFRow row32 = sheet.getRow(23);
               cell = row32.getCell(4);
               style2= cell.getCellStyle();
               style2.setFont(font3);
               cell.setCellStyle(style2);
               cell.setCellValue(PRO12X);
           
               XSSFRow row33 = sheet.getRow(23);
               cell = row33.getCell(6);
               style2= cell.getCellStyle();
               style2.setFont(font3);
               cell.setCellStyle(style2);
               cell.setCellValue(PRO12XQ);
               
           }
           
           //Repeater entries line 25 of spreadsheet (line 24 of POI)
            If  (PRO13X.length()>0){
               XSSFRow row34= sheet.getRow(24);
               cell = row34.getCell(4);
               style2= cell.getCellStyle();
               style2.setFont(font3);
               cell.setCellStyle(style2);
               cell.setCellValue(PRO13X);
           
               XSSFRow row35 = sheet.getRow(24);
               cell = row35.getCell(6);
               style2= cell.getCellStyle();
               style2.setFont(font3);
               cell.setCellStyle(style2);
               cell.setCellValue(PRO13XQ);
               
           }
           
           //Receivers entries line 26 of spreadsheet (line 25 of POI)
             If  (PRO14X.length()>0){
               XSSFRow row36 = sheet.getRow(25);
               cell = row36.getCell(4);
               style2= cell.getCellStyle();
               style2.setFont(font3);
               cell.setCellStyle(style2);
               cell.setCellValue(PRO14X);
               
               XSSFRow row37 = sheet.getRow(25);
               cell = row37.getCell(6);
               style2= cell.getCellStyle();
               style2.setFont(font3);
               cell.setCellStyle(style2);
               cell.setCellValue(PRO14XQ);
           }
           
           // Data Collector entries line 27 of spreadsheet (line 26 of POI)
              If  (PRO15X.length()>0){
                XSSFRow row38 = sheet.getRow(26);
               cell = row38.getCell(4);
               style2= cell.getCellStyle();
               style2.setFont(font3);
               cell.setCellStyle(style2);
               cell.setCellValue(PRO15X);
           
               XSSFRow row39 = sheet.getRow(26);
               cell = row39.getCell(6);
               cell.getCellStyle();
               style3.setFont(font3);
               cell.setCellStyle(style3);
               cell.setCellValue(PRO15XQ);
               System.out.println(PRO15X);
           }
        }
   
       try (FileOutputStream fos = new FileOutputStream(new File(filename2))) {
           workbook.write(fos);
       }
System.out.println("Done");
     }
}

5 months ago
Paul:

To start, I use Netbeans 8.2 IDE to develop the software. I do so because I use tons of input screens that interact with several Derby Databases --basically, a CRM type program, and I'm more comfortable with the GUI developer in Netbeans.

The variables are PRO1 to PRO10 (ADMIN Section on top of Spreadsheet); PRO1X to PRO15X (Product section below the Admin). I use a Derby DB which places data into these variables.

Then these variables are assigned to a row/cell location. Unfortunately, the amount of code I can post is limited to only a certain length so some of the codes were omitted. But the basic block used for placing into the spreadsheet is as follows. I use the same code for every row/cell entry. This is a DRAFT software program that I will clean up and improve once I have all the parts working. The problem is that the below code works (PRO1 to PRO10 and PRO1X to PRO5X) fine until it gets to PRO6X to PRO15X. The variables are PRO1X = Product Name, PRO1XQ = Product Quantity. These are posted to the spreadsheet (the Excel Spreadsheet has lookup tables for Costs, Markup, and Margin). I have tried everything I could think of but the problem is still there. Normally the code should place the database data from each variable to the location I specified in the code --and it does up to PRO5X. This program is a java "learning" program for me that I am doing to expedite and automate some of my own workloads. I don't do java professionally --just amateur stuff.

You can substitute any strings for the variables--doesn't matter since we're just placing strings to cell locations. I can also send you the entire java file. Email: txguy5199@gmail.com.


//tubes entries Line 13 of Spreadsheet (line 12 in POI)
            if (PRO1X.length()>0){
               XSSFRow row10 = sheet.getRow(12);
               cell = row10.getCell(4);
               style2 = cell.getCellStyle();
               style2.setFont(font3);
               cell.setCellStyle(style2);
               cell.setCellValue(PRO1X);
           
XSSFRow row11 = sheet.getRow(12);
               cell = row11.getCell(6);
               style2 = cell.getCellStyle();
               style2.setFont(font3);
               cell.setCellStyle(style2);
               cell.setCellValue(PRO1XQ);
               
           }
5 months ago
I wrote a program using the java POI to Excel that places product name and quantity to the spreadsheet. The spreadsheet has 15 rows with possible entries. After the POI posts the admin data at the top of the spreadsheet, the POI works on the first 4 lines without any issues, but then doesn’t post the other product names and quantities once it encounters a blank row entry.

The spreadsheet has 15 rows with name, price, quantity. I need to be able to place the product name and quantity anywhere on any of the 15 rows. For example, the first 4 rows (PRO1 – row 3, PRO4 – row 6, and PRO10 -row 69) get posted correctly to the spreadsheet. After rows 12 thru 15 are posted correctly, there are several blank rows (which have basically the same coding as the other selections but have empty variables for posting to the excel file). After the blank rows, the following rows get more product names and quantities. That’s where I have a problem. Those consecutive rows that do have product names and quantities for posting are not posted. So I end up with the product section only having the first 4 products in the spreadsheet. The rest of the products are not posted to the file.  

I checked, using print statements after each cell entry coding, for the variables (PRO1-PRO6 AND PRO1X THRU PRO66X) and they have the correct product name and quantity from the database. I then substituted a string within quotations instead of each variable and that also posted correctly to the spreadsheet.  

However, when I go back to using the variables only (after PRO5X entries) no posting occurs. I know my database Result statement does receive the product name and quantity correctly from the database. It correctly assigns the database data to the variables (PRO1, etc.). The variables do have data content correctly in the method (doDATA1() ) from accessing the database and in the method (set2EXCEL3() )for posting these variables to the Excel file. I can System print all the variables within the set2EXCEL3() method.

Please let me know what I’m doing incorrectly. Attached is a jpg shot of the spreadsheet rows and the missing data.


5 months ago