W

로컬 텍스트 엑셀 파일 읽기/쓰기

· 16년 전 · 5543

익스플로우의 보안에 허용만 가능하면 자바스크립트 상에서도 읽기/쓰기가 가능하다.

 

우선 text파일 읽고 쓰는 예제이다.(C:\\book1.txt를 읽고 씀)

 

=====================================================================================================================

<html>
<head>
<title>file save/load</title>

 

<script type="text/javascript">

    var fso=new ActiveXObject("Scripting.FileSystemObject");
    var filename="C:\\book1.txt";
    function savefile() {
        if (!fso.FileExists(filename)) {
            fso.CreateTextFile(filename,true);
        }
        var f=fso.OpenTextFile(filename,2,true);
        f.Write(myarea.innerHTML);
        f.Close();
    }
   
    function loadfile() {
        if (!fso.FileExists(filename)) {
            fso.CreateTextFile(filename,true);
        }
        var f=fso.OpenTextFile(filename,1);
        r=f.ReadAll();
        f.Close();
        myarea.innerHTML=r;
    }
   
   
    //function window.onload() {
    //    loadfile(filename);
    //}
</script>


</head>
<body>
 <table>
  <tr>
   <td>
    <div id=myarea contenteditable=true style="width:320;height:240;border:solid 2 inset;overflow:scroll;background-color:silver;"></div>
    <br><input type=button value=load onclick=loadfile()><input type=button value=save onclick=savefile()>
   </td>
  </tr>
 </table>
</form>
</body>
</html>

 

======================================Excel 파일 열고 쓰기 =================================================

- 쓰기 -

<script type="text/javascript">

// Declare the variables
var Excel, Book;

// Create the Excel application object.
Excel = new ActiveXObject("Excel.Application");

// Make Excel visible.
Excel.Visible = true;

// Create a new work book.
Book = Excel.Workbooks.Add()

// Place some text in the first cell of the sheet.
Book.ActiveSheet.Cells(1,1).Value = "This is column A, row 1";

// Save the sheet.
Book.SaveAs("C:\\book1.xls");

// Close Excel with the Quit method on the Application object.
Excel.Application.Quit();
</script>

 

- 열기 -

function StartExcel() {
var oExcel;

var oWBook;
oExcel = new ActiveXObject("Excel.Application");

oExcel.Visible = true;

oExcel.workbooks.open("C:/test.xls");

oExcel.Quit();

oExcel = null;
}

 

간단한 파일 읽기의 경우 상당히 유용할 수 있겠다..

 
[이 게시물은 관리자님에 의해 2011-10-31 17:16:08 PHP & HTML에서 이동 됨]
|
댓글을 작성하시려면 로그인이 필요합니다.

프로그램

+
제목 글쓴이 날짜 조회
15년 전 조회 2,027
15년 전 조회 841
15년 전 조회 1,309
15년 전 조회 1,287
15년 전 조회 3,061
15년 전 조회 3,442
15년 전 조회 2,109
15년 전 조회 1,568
15년 전 조회 2,196
15년 전 조회 1,687
15년 전 조회 1,306
15년 전 조회 3,990
15년 전 조회 1,651
15년 전 조회 1,730
15년 전 조회 3,005
15년 전 조회 1,693
15년 전 조회 4,396
15년 전 조회 2,593
15년 전 조회 3,366
15년 전 조회 2,000
15년 전 조회 2,241
15년 전 조회 1,519
15년 전 조회 4,580
15년 전 조회 4,226
15년 전 조회 4,026
15년 전 조회 5,420
15년 전 조회 3,664
15년 전 조회 2,019
15년 전 조회 1,962
15년 전 조회 2,110
16년 전 조회 1,820
16년 전 조회 4,245
16년 전 조회 3,141
16년 전 조회 2,296
16년 전 조회 1,890
16년 전 조회 2,096
16년 전 조회 2,607
16년 전 조회 1,681
16년 전 조회 2,605
16년 전 조회 1,934
16년 전 조회 2,061
16년 전 조회 1,712
16년 전 조회 2,395
16년 전 조회 1,724
16년 전 조회 2,144
16년 전 조회 2,323
16년 전 조회 1,409
16년 전 조회 1,471
16년 전 조회 2,119
16년 전 조회 5,544
16년 전 조회 1,851
16년 전 조회 2,354
16년 전 조회 2,551
16년 전 조회 1,715
16년 전 조회 1,502
16년 전 조회 2,431
16년 전 조회 5,138
16년 전 조회 2,403
16년 전 조회 3,070
16년 전 조회 1,942
16년 전 조회 3,808
16년 전 조회 4,652
16년 전 조회 3,289
16년 전 조회 2,538
16년 전 조회 2,626
16년 전 조회 2,865
16년 전 조회 2,376
16년 전 조회 5,744
16년 전 조회 3,566
16년 전 조회 1,566
16년 전 조회 1,891
16년 전 조회 5,267
16년 전 조회 2,512
16년 전 조회 3,593
16년 전 조회 2,869
16년 전 조회 1,740
16년 전 조회 5,571
16년 전 조회 2,693
16년 전 조회 6,167
16년 전 조회 2,131
16년 전 조회 4,202
16년 전 조회 3,228
16년 전 조회 2,401
16년 전 조회 2,425
16년 전 조회 4,586
16년 전 조회 3,484
16년 전 조회 3,010
16년 전 조회 3,164
16년 전 조회 2,272
16년 전 조회 1,958
16년 전 조회 1,874
16년 전 조회 1,578
16년 전 조회 1,869
16년 전 조회 2,093
16년 전 조회 1,784
16년 전 조회 5,034
16년 전 조회 4,034
16년 전 조회 1,970
16년 전 조회 1,738
16년 전 조회 2,464