Query Name in Excel Sheet tab
Hi Friends,
Instead of display Sheet 1 in the Excel sheet tab(Bex), is there a way we can display Query Name in the excel sheet tab? please let me know.
Thanks,
KK
Hi Kumar
Can you please share how it was solved ?
Ashish
Similar Messages
-
Hi Guys,
First of all thanks in advance any help much appriciated.
I am new in scripting and excel, i am looking for below solution as my job requires daily work of this kind and i came to know by automating this work lots of time can be saved.
Compare Server Names in Excel sheet from column1 with column 2 and exact matched server names should be saved in column 3 in same Excel sheet.
Looking solutions first using excel i.e.vlookup itself so that it will not require any approval in my job else using powersell ,vbscript.
Once again Thanks for you guys.
/Regards
Nitesh24inHi Edward,
Thanks once again
I have only changed excel file path and after that this is saved as below , i am not sure which three lines should be together in one line. Please advise.
$excel = New-Object -ComObject Excel.Application
$Workbook = $excel.Workbooks.Add("F:\NewDocsToReadNitesh26-May2013\Excel\test.xls")
$WorkSheet = $Workbook.Worksheets.Item(1)
$WorkSheet.Activate() | Out-Null
For ($i=1;$i -le $worksheet.UsedRange.Rows.Count;$i++) {
If ($worksheet.cells.item($i,1).value2 -eq $worksheet.cells.item($i,2).value2) {
$worksheet.cells.item($i,3).value2 = $worksheet.cells.item($i,1).value2
}$Workbook.Save()$excel.Quit()[System.Runtime.InteropServices.Marshal]::ReleaseComObject([System.__ComObject]$excel) | Out-Null
Thanks and Regards
Nitesh24in -
Result of a Query in an Excel Sheet??
Hi,
I am using sqlplus on Unix environment.
How can I get the results of a query (a multi column select query) into a excel sheet, which I can later SCP to my windows environment.
Kindly reply asap.
Thanks In Advance :)
AbhiYou might be able to use the sqlplus colsep command
http://download-east.oracle.com/docs/cd/B19306_01/server.102/b14357/ch12040.htm#sthref2716
SQL> set colsep ','
SQL> select * from emp;
EMPNO,ENAME ,JOB , MGR,HIREDATE , SAL, COMM, DEPTNO
7369,SMITH ,CLERK , 7902,17-DEC-80, 800, , 20
7499,ALLEN ,SALESMAN , 7698,20-FEB-81, 1600, 300, 30
7521,WARD ,SALESMAN , 7698,22-FEB-81, 1250, 500, 30
7566,JONES ,MANAGER , 7839,02-APR-81, 2975, , 20
7654,MARTIN ,SALESMAN , 7698,28-SEP-81, 1250, 1400, 30
7698,BLAKE ,MANAGER , 7839,01-MAY-81, 2850, , 30
7782,CLARK ,MANAGER , 7839,09-JUN-81, 2450, , 10
7788,SCOTT ,ANALYST , 7566,09-DEC-82, 3000, , 20
7839,KING ,PRESIDENT, ,17-NOV-81, 5000, , 10
7844,TURNER ,SALESMAN , 7698,08-SEP-81, 1500, 0, 30
7876,ADAMS ,CLERK , 7788,12-JAN-83, 1100, , 20
7900,JAMES ,CLERK , 7698,03-DEC-81, 950, , 30
7902,FORD ,ANALYST , 7566,03-DEC-81, 3000, , 20
7934,MILLER ,CLERK , 7782,23-JAN-82, 1300, , 40
14 rows selected.
SQL> -
In excel sheet tab name is not coming-urgent
hi all,
one small rewquirement. if u run this test program it opens a excel sheet which contains signle tab. here tab name is not coming. i dont no hot to display tabname here.anybody can make the changes and send me the code.
i am sending my code below.
thanks,
maheedhar.t
REPORT ytestvij MESSAGE-ID zv.
TABLES sscrfields.
TYPE-POOLS: icon.
TYPES : BEGIN OF zfnames_ds,
reptext TYPE reptext,
END OF zfnames_ds.
TYPE-POOLS ole2 .
DATA: wa_fntxt TYPE smp_dyntxt.
DATA : wa_t75_booking TYPE zvt75_booking_h,
t_t75_booking TYPE STANDARD TABLE OF zvt75_booking_h.
DATA : wa_fields TYPE dfies,
t_fields TYPE STANDARD TABLE OF dfies.
DATA : wa_fnames TYPE zfnames_ds,
t_fnames TYPE STANDARD TABLE OF zfnames_ds.
handles for OLE objects
DATA: h_excel TYPE ole2_object, " Excel object
h_mapl TYPE ole2_object, " list of workbooks
h_map TYPE ole2_object, " workbook
h_zl TYPE ole2_object, " cell
h_f TYPE ole2_object. " font
DATA h TYPE i.
DATA : lin TYPE i.
data: excel type ole2_object,
application type ole2_object,
books type ole2_object,
book type ole2_object,
sheet type ole2_object,
cell type ole2_object,
column type ole2_object.
PARAMETERS : p_input TYPE localfile.
Add button to application toolbar
SELECTION-SCREEN FUNCTION KEY 1. "Will have a function code of 'FC01'
INITIALIZATION.
Add displayed text string to buttons
wa_fntxt-icon_id = icon_xls.
wa_fntxt-icon_text = 'Input File template'.
wa_fntxt-quickinfo = 'T75 Header Data'.
sscrfields-functxt_01 = wa_fntxt.
AT SELECTION-SCREEN.
IF sscrfields-ucomm = 'FC01'.
do nothing
PERFORM open_excel.
ENDIF.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_input.
PERFORM get_filename USING p_input.
START-OF-SELECTION.
*set pf-status 'ONE'.
END-OF-SELECTION.
WRITE : lin.
*& Form GET_FILENAME
text
--> p1 text
<-- p2 text
FORM get_filename USING p_file TYPE rlgrap-filename . "localfile.
DATA : w_rc TYPE i.
DATA : wa_file_table TYPE file_table ,
t_file_table TYPE STANDARD TABLE OF file_table.
CALL METHOD cl_gui_frontend_services=>file_open_dialog
EXPORTING
WINDOW_TITLE =
DEFAULT_EXTENSION =
DEFAULT_FILENAME =
FILE_FILTER =
INITIAL_DIRECTORY =
MULTISELECTION =
CHANGING
file_table = t_file_table[]
rc = w_rc
USER_ACTION =
EXCEPTIONS
file_open_dialog_failed = 1
cntl_error = 2
error_no_gui = 3
OTHERS = 4
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
LOOP AT t_file_table INTO wa_file_table.
p_file = wa_file_table-filename.
ENDLOOP.
ENDFORM. " GET_FILENAME
*& Form open_excel
text
--> p1 text
<-- p2 text
FORM open_excel.
SELECT * FROM ZVT75_BOOKING_H
INTO TABLE t_t75_booking
UP TO 10 ROWS.
start Excel
CREATE OBJECT h_excel 'EXCEL.APPLICATION'.
PERFORM err_hdl.
SET PROPERTY OF h_excel 'Visible' = 1.
PERFORM err_hdl.
get list of workbooks, initially empty
CALL METHOD OF h_excel 'Workbooks' = h_mapl.
PERFORM err_hdl.
add a new workbook
CALL METHOD OF h_mapl 'Add' = h_map.
PERFORM err_hdl.
output column headings to active Excel sheet
PERFORM fill_cell USING 1 1 1 'Financial year'.
PERFORM fill_cell USING 1 2 1 'Financial quarter'.
PERFORM fill_cell USING 1 3 1 'Customer number'.
PERFORM fill_cell USING 1 4 1 'Booking Year'.
PERFORM fill_cell USING 1 5 1 'Financial quarter'.
PERFORM fill_cell USING 1 6 1 'Contract type'.
PERFORM fill_cell USING 1 7 1 'Sub Contract type'.
PERFORM fill_cell USING 1 8 1 'Customer purchase order number'.
PERFORM fill_cell USING 1 9 1 'Booking Amount'.
PERFORM fill_cell USING 1 10 1 'Currency Key'.
LOOP AT t_t75_booking into wa_t75_booking.
copy items to active EXCEL sheet
H = SY-TABIX + 1.
PERFORM FILL_CELL USING H 1 0 wa_t75_booking-BOOKYEAR.
PERFORM FILL_CELL USING H 2 0 wa_t75_booking-BOOKQTR.
PERFORM FILL_CELL USING H 3 0 wa_t75_booking-.
PERFORM FILL_CELL USING H 4 0 wa_t75_booking-BOOKYEAR.
PERFORM FILL_CELL USING H 5 0 wa_t75_booking-BOOKQTR.
ENDLOOP.
disconnect from Excel
FREE OBJECT h_excel.
PERFORM err_hdl.
ENDFORM. " open_excel
*& Form ERR_HDL
outputs OLE error if any *
--> p1 text
<-- p2 text
FORM err_hdl.
data test type sy-subrc.
test = sy-subrc.
IF test <> 0.
Message e000(ZV) with 'Error in OLE-Automation:'.
STOP.
ENDIF.
ENDFORM. " ERR_HDL
FORM FILL_CELL *
sets cell at coordinates i,j to value val boldtype bold *
FORM fill_cell USING i j bold val.
CALL METHOD OF h_excel 'Cells' = h_zl EXPORTING #1 = i #2 = j.
set property of sheet 'Name' = 'T75'.
PERFORM err_hdl.
SET PROPERTY OF h_zl 'Value' = val .
PERFORM err_hdl.
GET PROPERTY OF h_zl 'Font' = h_f.
PERFORM err_hdl.
SET PROPERTY OF h_f 'Bold' = bold .
PERFORM err_hdl.
ENDFORM.Hi,
Look at the below thread, i posted complete code in this one, just copy that Program and past in your SAP and run the Program, it will create 3 sheets with the names also, then look at the Sheet name in the code, you will understand where to add the code
Re: format an excel
Regards
Sudheer -
Mapping query result to excel sheet
Hi Experts,
i have a requirement where in i need to map the result into particular cellls of the excel sheet, because the excel sheet acts as front end which has graphs and by just putting the result in particular cells of excel the graph is automatically generated, so is there any way where i can map the result cells into particulat cells in excel?
Thank you.Hi Shetty,
You might have stopped reading this thread since you have the answer you need for now. From experience, let me tell you what might happen next.
If the query definition is ever changed ... say, a new characteristic is added because a different user has a slightly different need ... the result table will move down by a few rows and your equation no longer works.
If you think this might happen, let me tell you a very easy way to get around it.
1. Name the range(s) you will use. If the first result is in cell B31 on Sheet1, then go to cell B31 on Sheet1 and Select Insert>>Name>>Define. Call it something you will remember, like "LastMonthSales" (no spaces, but underline is OK)
2. use the range name in your formula. This happens automatically, in fact. If you press = then click on cell B31, Excel will automatically use the range name instead of the range address. Excel LIKES names.
3. now, go to the Visual Basic Editor (Tools >> Macro >> Visual Basic Editor; or, Alt+F11). In your workbook, there should be a subroutine as follows:
Sub SAPBEXonRefresh(queryID As String, resultArea As Range)
If you do not find it, add it. This probably also means that you are using Excel 2002 or later and have not set your Macro security to "trust access to Visual Basic Project"; so, change that security setting (Tools >> Options >> Security >> Macro Settings).
The visual basic code is very simple. For each result that you need to map you will want one line of code like this one:
resultArea.Cells(4, 2).Name = "LastMonthSales"
The Cells(4, 2) are counted from the top left of the result table. So, in this case if B31 = Cells(4,2), then the top left of my result table must have been in cell A28 in Excel.
This subroutine will be run automatically every time that the query is refreshed. So, if the result table moves, the names will move with it. One less thing to worry about.
If you do not think you need to do this today, don't! No sense in doing work that is not necessary. But, save this. I suspect that some day you will need it.
- Pete -
Change Excel sheet tab color using Open XML dll
Hi,
I want to change the sheet tab color of an excel Xlsx document. I am using the following code but it does not set the sheet color. I get object reference exception when I set the sheet tab color.
public static string filepath = @"C:\Test\Book1.xlsx";
private static void ChangeSheetcolor()
try
using (SpreadsheetDocument spreadSheetDocument = SpreadsheetDocument.Open(filepath, false))
WorkbookPart workbookPart = spreadSheetDocument.WorkbookPart;
IEnumerable<Sheet> sheets = spreadSheetDocument.WorkbookPart.Workbook.GetFirstChild<Sheets>().Elements<Sheet>();
//my code
WorksheetPart worksheetPart =
GetWorksheetPartByName(spreadSheetDocument, "Sheet1");
if (worksheetPart != null)
// worksheetPart.Worksheet.SheetProperties.TabColor.Rgb = DocumentFormat.OpenXml.HexBinaryValue.FromString("Red");
worksheetPart.Worksheet.SheetProperties.TabColor.Rgb = DocumentFormat.OpenXml.HexBinaryValue.FromString("#CCCCCC");
// Save the worksheet.
worksheetPart.Worksheet.Save();
catch (Exception ex)
private static WorksheetPart
GetWorksheetPartByName(SpreadsheetDocument document,
string sheetName)
IEnumerable<Sheet> sheets =
document.WorkbookPart.Workbook.GetFirstChild<Sheets>().
Elements<Sheet>().Where(s => s.Name == sheetName);
if (sheets.Count() == 0)
//does not exist
return null;
string relationshipId = sheets.First().Id.Value;
WorksheetPart worksheetPart = (WorksheetPart)
document.WorkbookPart.GetPartById(relationshipId);
return worksheetPart;
How to change the sheet tab color using Open XML dlls.
Thanks
AshokHi J_Prasanna,
I'm afraid that it's not possible with OpenXML SDK, but it's possible if you use Excel PIA along with Internet Explorer. Use the Internet Explorer COM object to render the HTML content, then copy the document, use the Paste method of the Worksheet object
to paste the text with format.
Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")
With IE
.Visible = False
.Navigate "about:blank"
.document.body.InnerHTML = Sheets("Sheet1").Range("A1").Value
.document.body.createtextrange.execCommand "Copy"
ActiveSheet.Paste Destination:=Sheets("Sheet1").Range("A1")
.Quit
End With
The code is similar if you use managed project.
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey. -
How can I give a name to excel sheet and open another one?
Hello!
I use CSVWriter for writing in excel file.
I have 2 questions:
1. How can I give a name to a Sheet in excel file?
2. How can I save the first Sheet and open another one with a different name?
Thanks!This is the equivalent in Apache POI which may or may not help. I've never used CSVWriter.
HSSFSheet sheet1 = workbook.createSheet("sheet1Name");
HSSFSheet sheet2 = workbook.createSheet("sheet2Name");Then you can use either sheet object to write your contents. Look at the documentation for CSVWriter that pertains to sheets as it should tell you how. -
Download BW query names in excel
Hi Guys, This is BW question. Can someone please tell me if I want to copy or download all the query names (not queries) in excel what is the procedure for that?
Thanks in advance.
Kam.Hi,
you have to combine (view) / or create a query (SQVI / SQ01) with tables RSRREPDIR and RSZELTTXT.
The link is
RSRREPDIRCOMPUID = RSZELTTXTELTUID
RSRREPDIROBJVERS = RSZELTTXTOBJVERS
QUERY_TECCH= RSRREPDIR~COMPID
QUERY_TXTSH= RSZELTTXT~TXTSH
QUERY_TXTLG= RSZELTTXT~TXTLG
and then dump it to excel...
You can also use the technical business content 0TCT* objects.
hope this helps...
Olivier. -
Query output to excel sheet...pls solve my problem here !
Hi all,
I have written a procedure which accepts parameters and generate a web page.
The web page generated records as fetched from cursor within procedure.
My requirement is to generate it as a excel sheet once run through url.
I am getting as a text inspite using
owa_util.mime_header('ms-excel');
within my code.....
can you pls help or send me code which could do above task...:)
Thanks in advance.
Regards
RavikanthTry this instead :
OWA_UTIL.MIME_HEADER('application/vnd.ms-excel');
Barry C
http://www.myoracleportal.com -
Excel sheet tabs white on white after 10.4.7
Hello,
I updated on 10.4.7 today.
Now when I open a Excel (X, 10.1.6) file, the registry tabs of the sheets (tables and diagrams) contain white text on white background. Yesterday I still worked on the same file and everything was OK then.
It is a bit annoying - does anyone have a clue how to get black text again?
Thank you.
Powerbook G4, 1.25GHz Mac OS X (10.4.3)> The current version of Excel is 11.2.3.
I just had a look (having updated to OS 10.4.7) and
it seems OK.
Do you have a particular reason for not updating
Office - which is free?
Excel 11.x.x is a part of Office 2004
Excel 10.x.x is a part of Office X
The Upgrade Office X --> Office 2004 is a 'major upgrade', which has to be paid for. It's not free...
However, I found another Excel security update (to 10.1.7) and after installing this one I had black text again.
Don't ask me if it stays black though -
HI All,
I need the sql query output in Excel sheet.
We use sqlunload for this.
But my requirement is to export
2 sql query in 2 tabs of a single excel sheet.
Please let m eknow how to process this.
Thanks,
LonyAny idea how to work on this one?
-
Generating Date Time Stamped Excel Sheet
Hi
I am working on Data Logging project and requirement is to log data data to excel sheet at one per second. Moreover the name of excel sheet should be automatic date time stamp generated. Can anybody help me in generating datetime stamp file name for this file which I have downloaded from ni website.
Thanks
Solved!
Go to Solution.
Attachments:
continuouswritespead.vi 26 KBYour program does not create an Excel File. It creates a text file that Excel is able to open up and import.
As it is right now, the name of the file you create is determined by a dialog box that pops up with the old version of the Open/Create/Replace file that you have. If you want the program to determine the file name, you need to build a file path out of string data in the same manner you are using the string coming from the Get Date/Time String function you have inside the loop.
Message Edited by Ravens Fan on 04-25-2010 02:59 PM -
Hi,
Being an experienced Excel user before Power BI, I am just starting to explore the M and Power Query capabilities, and need help already (ain't easy to google this use case somehow):
I need to import the table which sits in the Excel file with header row in the row 17 of Excel sheet, with some metadata header in the preceding rows of the columns A and B.
01: Report name, Quick Report
02: Report Date, 1/1/2014
17: Employee Name, Manager, etc...
18: John Doe, Matt Beaver, etc.
Both (a) direct attempt to load as Excel file and (b) the indirect way through [From Folder] and formula in custom column -- both lead to the same error: "[DataFormat.Error] External table is not in the expected format."
Specifically, I tried to use the [Power Query -> From File -> From Folder] functionality, select an Excel file and add a custom column to access the binary content: [Add Custom Column] with formula "=Excel.Workbook([Content])".
It looks like Power Query expects a rectangular range with headers full-width followed by a contiguous table range to import anything, and refuses to load if that is not the case...
QUESTION: Is there any way to load whatever-formatted data from Excel first, and then manipulate the overall imported range (like referring to rows starting from 17th using "Table.SelectRows" etc.) to read the actual data? Reading and using
the metadata from header would be a bonus, but that comes second... The main issue is to get something from a non-regular Excel file to later work with using M formulae ...
Thanks!
SAMFinally found the answer to this one in ():
You Cannot Open a Password-Protected Workbook
If the Excel workbook is protected by a password, you
cannot open it for data access, even by supplying the correct password with
your connection settings, unless the workbook file is already open in the
Microsoft Excel application. If you try, you receive the following error
message:
Could not decrypt file.
ANSWER: So, will have either weave in the work with temporary unprotected files or requires opening them before updating the data source (although this almost defeats the purpose of automation...)
ANSWER to ORIGINAL QUESTION: password was preventing Power Query from reading the Excel file. For solution see above.
Thanks anyway for participation and inspiration, Imke! -
Identifying text file names and importing on single Excel sheet
Hey!
Does anybody can help me with Excel VBA macro code in order to import data from text files into single Excel spread sheet? I want to create User Form where user can select start and end date of interest and macro code will import
bunch of text files depending on user demands...
My text files are named: 20130619004948DataLog.txt (meaning: yyyy mm dd hh mm ss). Text file contains recordings for each 15 seconds... It would be great to omit time tail (meaning that user can only specify date). Text files for one day of interest (I have
text files covering whole year):
20130619004948DataLog.txt
20130619014948DataLog.txt
20130619024948DataLog.txt
20130619034948DataLog.txt
20130619044948DataLog.txt
20130619054948DataLog.txt
20130619064948DataLog.txt
20130619074948DataLog.txt
20130619084948DataLog.txt
20130619094948DataLog.txt
20130619104948DataLog.txt
20130619114948DataLog.txt
20130619124948DataLog.txt
20130619134948DataLog.txt
20130619144948DataLog.txt
20130619154948DataLog.txt
20130619164948DataLog.txt
20130619174948DataLog.txt
20130619184948DataLog.txt
20130619194948DataLog.txt
20130619204948DataLog.txt
20130619214948DataLog.txt
20130619224948DataLog.txt
20130619234948DataLog.txt
Option Explicit
Sub SearchFiles()
Dim file As Variant
Dim x As Integer
Dim myWB As Workbook
Dim WB As Workbook
Dim newWS As Worksheet
Dim L As Long, t As Long, i As Long
Dim StartDateL As String
Dim EndDateL As String
Dim bool As Boolean
bool = False ' to check if other versions are present
StartDateL = Format(Calendar1, "yyyymmdd")
EndDateL = Format(Calendar2, "yyyymmdd")
' I am using Userform asking user to select the date and time range of interet,
' However, I want to use only the date to filter the files having the name with that particular date
file = Dir("c:\myfolder\") ' folder with all text files
' I need assistance with the following part:
'1) How to filter and select the files between StartDateL and EndDateL_
'(including files with that dates as well)?
While (file <> "")
If InStr(file, StartDateL) > 0 Then 'Not sure if the statements inside parenthesis is correct
bool = True
GoTo Line1:
End If
file = Dir
Wend
Line1:
If Not bool Then
file = "c:\myfolder\20130115033100DataLog.txt" 'Just for a test that the code works as intended
End If
'This part for the selected text files to be loaded on a single Excel Sheet.
Set myWB = ThisWorkbook
Set newWS = Sheets(1)
L = myWB.Sheets(1).Cells(Rows.Count, "A").End(xlUp).Row
t = 1
For x = 1 To UBound(file)
Workbooks.OpenText Filename:=file(x), DataType:=xlDelimited, Tab:=True, Semicolon:=True, Space:=False, Comma:=False
Set WB = ActiveWorkbook
WB.Sheets(1).UsedRange.Copy newWS.Cells(t, 2)
t = myWB.Sheets(1).Cells(Rows.Count, "B").End(xlUp).Row + 1
WB.Close False
Next
myWB.Sheets(1).Columns(1).Delete
Application.ScreenUpdating = False
Rows("1:1").Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
End Sub- Make a new Excel file
- Open the VBA editor
- Add a Userform
- Place 2 text boxes and 1 command button on that form
- Paste all code below into the code module of the form
- Download this file:
https://dl.dropboxusercontent.com/u/35239054/FileSearch.cls
- In the VBA editor press CTRL-M and import that file
- Save the Excel file in the directory that contain your text files
- Run the form
You can format the columns of the sheet as you like, e.g. column E:H should be a number with 5 decimal places. The top row can contain some headings. My code did not affect the formatting or the headings.
Andreas.
Option Explicit
Private Sub UserForm_Initialize()
'Just a sample
Me.TextBox1.Value = FormatDateTime(Now, vbGeneralDate)
Me.TextBox2.Value = FormatDateTime(Now, vbShortDate)
End Sub
Private Sub CommandButton1_Click()
Dim StartDate As Date, EndDate As Date
Dim FS As New FileSearch
Dim R As Range
Dim ThisFile As Variant
Dim ThisDate As Date
Dim Data As Variant
Dim Count As Long
'Be sure we have 2 dates
If Not IsDate(Me.TextBox1.Value) Then
Me.TextBox1.SetFocus
MsgBox "No start date"
Exit Sub
End If
If Not IsDate(Me.TextBox2.Value) Then
Me.TextBox2.SetFocus
MsgBox "No end date"
Exit Sub
End If
'Convert to real dates
StartDate = CDate(Me.TextBox1.Value)
EndDate = CDate(Me.TextBox2.Value)
'Time part given?
If Fix(EndDate) = EndDate Then
'No include all files for this day
EndDate = EndDate + TimeSerial(23, 59, 59)
End If
'Correct order?
If StartDate > EndDate Then
ThisDate = EndDate
EndDate = StartDate
StartDate = ThisDate
End If
With FS
'Same path as our file
.LookIn = ThisWorkbook.Path
.FileName = "*DataLog.txt"
'Search all files sort by file name
If .Execute(msoSortByFileName, msoSortOrderAscending) = 0 Then
MsgBox "No data files found in " & .LookIn
Exit Sub
End If
'Clear previous data
Set R = Range("A2").CurrentRegion
If R.Row < 2 Then Set R = R.Offset(1)
R.ClearContents
'Show the user that we are working
Application.Cursor = xlWait
DoEvents
For Each ThisFile In .FoundFiles
'Get the date from the file name
ThisDate = Filename2Date(ThisFile)
'Between our dates?
If (ThisDate >= StartDate) And (ThisDate <= EndDate) Then
'Import at the end of the data
Set R = Range("A" & Rows.Count).End(xlUp).Offset(1)
Data = ReadCSV(ThisFile)
R.Resize(UBound(Data) + 1, UBound(Data, 2) + 1) = Data
Count = Count + 1
End If
Next
End With
'Done
Application.Cursor = xlDefault
If Count = 0 Then
MsgBox "No files match your dates"
Else
MsgBox Count & " files imported"
'Hide the form
Me.Hide
End If
End Sub
Private Function Filename2Date(ByVal Fullname As String) As Date
'Convert e.g "C:\20130601142648DataLog.txt" to the date "01.06.2013 14:26:48"
Dim i As Long, j As Long
i = InStrRev(Fullname, "\")
If i > 0 Then Fullname = Mid(Fullname, i + 1)
Fullname = JustNumbers(Fullname)
If Len(Fullname) <> 14 Then Exit Function
Filename2Date = _
DateSerial(Mid(Fullname, 1, 4), Mid(Fullname, 5, 2), Mid(Fullname, 7, 2)) + _
TimeSerial(Mid(Fullname, 9, 2), Mid(Fullname, 11, 2), Mid(Fullname, 13, 2))
End Function
Private Function JustNumbers(ByVal What As String) As String
'Return only numbers from What (by Rick Rothstein)
Dim i As Long, j As Long, Digit As String
For i = 1 To Len(What)
Digit = Mid$(What, i, 1)
If Digit Like "#" Then
j = j + 1
Mid$(What, j, 1) = Digit
End If
Next
JustNumbers = Left$(What, j)
End Function
Private Function ReadCSV(ByVal Fullname As String) As Variant
'Read a CSV file into an array
Const LDelim = vbCrLf 'Line delimiter
Const FDelim = ";" 'Field delimiter
Dim hFile As Integer
Dim Buffer As String
Dim Lines, Line, Data
Dim i As Long, j As Long
'Be sure the file exists
If Dir(Fullname) = "" Then Exit Function
'Open and read all data
hFile = FreeFile
Open Fullname For Binary Access Read As #hFile
Buffer = Space(LOF(hFile))
Get #hFile, , Buffer
Close #hFile
'Split into lines
Lines = Split(Buffer, LDelim)
'Split the first line and prepare the output
'Note: I assume that all lines have the same number of fields
Line = Split(Lines(0), FDelim)
ReDim Data(0 To UBound(Lines), 0 To UBound(Line))
For i = 0 To UBound(Lines)
Line = Split(Lines(i), FDelim)
For j = 0 To UBound(Line)
'Parse the fields
If IsDate(Line(j)) Then
Data(i, j) = CDate(Line(j))
ElseIf IsNumeric(Line(j)) Then
Data(i, j) = CDbl(Line(j))
Else
Data(i, j) = Line(j)
End If
Next
Next
ReadCSV = Data
End Function -
How to populate the data to second sheet tab in excel
Hai,
I need to populate data to the second sheet tab of excel sheet .
Below is the code wherein I added datas to first sheet of the excel sheet.Can anyone help me in this ?
<%
response.setHeader("Cache-Control","max-age=0"); // HTTP 1.1
response.setHeader("Pragma","public"); // HTTP 1.0
response.setDateHeader ("Expires", 0); // prevents caching at the proxy server
response.setContentType("application/ms-excel;charset=UTF-8");
response.setHeader("Content-Disposition","attachment;filename=Test.xls");
%>
<html xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns="http://www.w3.org/TR/REC-html40">
<xml>
<x:ExcelWorkbook>
<x:ExcelWorksheets>
<x:ExcelWorksheet>
<x:Name>Sheet-1</x:Name>
<x:WorksheetOptions>
</x:WorksheetOptions>
</x:ExcelWorksheet>
<x:ExcelWorksheet>
<x:Name>Sheet-2</x:Name>
<x:WorksheetOptions>
</x:WorksheetOptions>
</x:ExcelWorksheet>
</x:ExcelWorksheets>
<x:WindowHeight>9090</x:WindowHeight>
<x:WindowWidth>15180</x:WindowWidth>
<x:WindowTopX>120</x:WindowTopX>
<x:WindowTopY>15</x:WindowTopY>
<x:ProtectStructure>False</x:ProtectStructure>
<x:ProtectWindows>False</x:ProtectWindows>
</x:ExcelWorkbook>
</xml>
<body link=blue vlink=purple>
<table x:str border=0 cellpadding=0 cellspacing=0 width=192 style='border-collapse:collapse;table-layout:fixed;width:144pt'>
<tr height=17 style='height:12.75pt'>
<td height=17 align=right >HELLO</td>
<td align=right >HI</td>
<td align=right >GOOD BYE</td>
</tr>
</table>
</body>
</html>Hi,
It's been a while since I did this stuff so I apologise if my advice is out of date.
This is actually more of a Micro$oft question as this is their propriety SpreadSheet Markup Language so POI probably won't help. Also, you might want to look at using the default namespace of "urn:schemas-microsoft-com:office:spreadsheet" as this is the more current implementation unless you need to be backward compatible.
On your specific question, I think that you should be able to put the table tag (SSML not HTML) inside the worksheet and then create the rows and cells in there. I've never tried mixing the 2 markup languages though so I'm not sure how to get the HTML to go into the correct sheet.
Sorry I couldn't help more :-(
Maybe you are looking for
-
Need help restoring Windows 8 Single Language and updating to 8.1
To cut a very long story short, I have 2 PC's from different manufacturers. One is mine and the other is a friend's. Both came with Genuine OEM Windows 8 Single Language preinstalled. When attempting to update my PC to 8.1 from 8.0, it failed to boot
-
Mac Mini first boot and bluetooth keyboard not recognised
Hi Apple Support Community- I have just purchased a brand new Mac Mini and App Wireless Keyboard. Unfortunately upon first boot, the Mac Mini is requesting I connect my bluetooth keyboard by switching it on, however even though the green light flash
-
My computer doesn't recognize my shuffle
So I have a refurbished shuffle and recently got a refurbished laptop. I have downloaded itunes, but when I plug my shuffle into the computer a message pops up saying "Device not recognized" Why is this? It works fine on my desktop.
-
hi, i am using jsp:plugin to handle applets.when i am placing the applet class file in the same jsp files directory itself its working.but,when i am placing the applet class file in the WEB-INF/classes directory it couldn't point the class file and i
-
Double leafs in non-time dependant hierarchies
Hi I'd like to ask you if someone's dealt with double leafs in a non-time dependant hierarchy; this would be something like this: |_Char.A_|_Chr.B_|_Chr.C |_SERV_|_JEFE1_|_COMER1_|_100 EUR |_SERV_|_JEFE2_|_COMER1_|_ 50 EUR PROD JEFE1 COMER1 _400 EUR